更改jLabel可见性



我是Netbeans和Java的新手,对jPanels上的jLabels有问题。我有一个带有jPanel的jTabbedPane。我在jPanel上有一个jLabel。我想将jLabel的可见性设置为false,但它似乎不起作用。当我运行程序时,标签仍然可见。我不明白为什么。

Label label = new Label("jLabel1");
label.setVisible(false);

您可以在initComponents()中设置它;

package my.tt;
public class NewJFrame extends javax.swing.JFrame {
    public NewJFrame() {
        initComponents();
    }
    private void initComponents() {
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1      = new javax.swing.JPanel();
        label        = new javax.swing.JLabel("jLabel1");
        label.setVisible(false);
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        [...]
        jTabbedPane1.addTab("tab1", jPanel1);
        [...]
        pack();
    }
    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            [...]
        }
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }
    private javax.swing.JLabel label;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTabbedPane jTabbedPane1;
}

相关内容

  • 没有找到相关文章