Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jpanel';jLayeredPane中的可见性问题_Java_Swing - Fatal编程技术网

Java Jpanel';jLayeredPane中的可见性问题

Java Jpanel';jLayeredPane中的可见性问题,java,swing,Java,Swing,我的代码无法显示所需的JPanel,该JPanel最初具有setVisible(false),但当执行某些操作时,其可见性随后设置为true,但不会显示在屏幕上 即使我最初将setVisible设置为true,它也不会显示。我已将代码附加到PasteBin上 有两个分层窗格,一个是jLayeredPane1,另一个是jLayeredPane2。现在,在JLayeredPane1中有两个JPanel,recordingPanel和reRecordingPanel 最初加载小程序时,reRecord

我的代码无法显示所需的JPanel,该JPanel最初具有setVisible(false),但当执行某些操作时,其可见性随后设置为true,但不会显示在屏幕上

即使我最初将setVisible设置为true,它也不会显示。我已将代码附加到PasteBin上

有两个分层窗格,一个是jLayeredPane1,另一个是jLayeredPane2。现在,在JLayeredPane1中有两个JPanel,recordingPanel和reRecordingPanel

最初加载小程序时,reRecordingPanel的可见性设置为可见(false)。当第一轮录制完成时,它将变为可见,而以前可见的recordingPanel现在变为不可见。这很好用

我的问题是我想在另一个JLayeredPanel上做同样的事情,它包含timerPanel和ListingPanel

问题就在这里:timerPanel的可见性最初是真实的,但当用户按下“侦听”按钮时,它应该是不可见的,侦听面板应该是可见的,但事实并非如此

我无法看到正在收听的播放机,尽管我已将其可见性设置为true。正如我前面所说的,即使我最初将其可见性设置为true,它也不会显示

我做错了什么

这与比赛条件有关吗

问题出在这个代码片段中

if (getCurrentState() == RecorderUI.LISTENING_STATE) {

            // switch panel
            this.timerPanel.setVisible(true);
            this.listeningPanel.setVisible(false);

            // switch button
            this.reRecordingButton.setEnabled(true);
            this.saveButton.setEnabled(true);

            this.listenButton.setText("Listen");

            this.setCurrentState(NORMAL_STATE);

            // according to player's state wise
            this.closePlayer();

            log.info(" player closed ");

        } else {

            // switch panel
            this.timerPanel.setVisible(false);
            this.listeningPanel.setVisible(true);

            log.info(" visibility of listeningPanel is "
                    + this.listeningPanel.isVisible());

            // switch button
            this.reRecordingButton.setEnabled(false);
            this.saveButton.setEnabled(false);

            this.listenButton.setText("Close");

            this.setCurrentState(LISTENING_STATE);

            this.startPlayer();

            log.info(" now playing ");
        }

    }

调试时,我发现matisse已将jPanel(ListingPanel)的高度和宽度设置为-1,-1,这就是它不显示在屏幕上的原因。我已通过手动设置解决了此问题


谢谢大家

为什么要使用
this.timerpanel.setVisible(false)
而不是
timerpanel.setVisible(false)
?我以前从未见过这种情况。@Pureferret
这个
引用类的当前实例。在某些情况下,它可以帮助消除类变量与方法参数(通常是set方法)之间的歧义。它也用于其他情况…@GuillaumePolet我知道
这个
是如何工作的,但是
这个。somethingElse.somethod
告诉我对属于
这个
的公共变量
somethingElse
执行
somethod
(或者在这种情况下它可能是私有的)。我不认为你能做这个.instance。也许现在太早了,快2000英里了?将其拆分为大约50到100以隔离问题,或者换句话说:显示一个SSCCE而不是那个怪物:-)@Mihir您已经解释了问题,是的,但问题可能几乎在这2000行中的任何地方。使用a可以帮助我们发现问题,并帮助您。