2016-03-15 110 views
0

我有一個代碼,當我點擊jButton時,它應該設置爲不可見,而另一個已經設置爲FALSE的JButton應該爲TRUE,setVisible (true)不起作用。jbutton setVisible(false)設置回setVisible(true)不起作用

buttonGrid[row][col] = new JButton(); 
add(buttonGrid[row][col]); 
buttonGrid[row][col].setVisible(false); 

該代碼工作時,我設置爲false,如果我設置爲true。它不工作

JButton selectedBtn = (JButton) evt.getSource(); 
      selectedBtn.setVisible(true); 

      for (int row = 0; row < buttonGrid.length; row++) { 
       for (int col = 0; col < buttonGrid[row].length; col++) { 

        if(buttonGrid[row][col] == selectedBtn){ 
         if ((row-1)>=0 && !buttonGrid[row - 1][col].isVisible()) { 
          System.out.println("1"); 
          int c = row-1; 

          buttonGrid[c][col] = selectedBtn; 
          buttonGrid[c][col].setVisible(true); 
          buttonGrid[row][col].setVisible(false); 
         } 
          * 
          * 
          * 

我要的是我會試着點擊按鈕號碼2.按鍵號碼3應該是可見的和按鈕2號是無形的。

+1

PLZ提供一個可運行example.what!是你看不見的按鈕cliking刷新JPanel的? –

回答

1

你必須使用以下方法

  • panel.revalidate();
  • panel.repaint();
相關問題