【问题标题】:jbutton setVisible(false) setting back to setVisible(true) not workingjbutton setVisible(false) 设置回 setVisible(true) 不起作用
【发布时间】:2016-03-15 16:41:23
【问题描述】:

我有一个代码,当我单击 jButton 时,它应该设置为不可见,而另一个已经设置为 FALSE 的 JButton 应该为 TRUE,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 号按钮是不可见的。

【问题讨论】:

  • 请提供一个可运行的例子。什么!你在点击隐形按钮吗?

标签: java eclipse jbutton grid-layout visible


【解决方案1】:

您必须使用以下方法刷新 JPanel

  • panel.revalidate();
  • panel.repaint();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 2013-05-14
    • 2015-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    相关资源
    最近更新 更多