0
私はモニタの数を検出し、同じ数のラベルを表示したいと思います。しかし、目に見えないものは働かない。 InitialMonitorsDetection - DetectMonitorsのすべてのラベルを非表示にしたい - いくつかのラベルを表示しますが、ラベルは常に表示されます。私はJavaの初心者ですので、ごめんなさい。助けてくれてありがとう。 `java jLabel.setVisible not working
public MainFrame() {
initComponents();
}
public void InititalMonitorsDetection() {
Monitor1.setVisible(false);
Monitor2.setVisible(false);
Monitor3.setVisible(false);
Monitor4.setVisible(false);
Monitor5.setVisible(false);
Monitor6.setVisible(false);
Monitor7.setVisible(false);
Monitor8.setVisible(false);
Monitor9.setVisible(false);
Monitor10.setVisible(false);
}
public void DetectMonitors() {
JLabel[] ArMonitors;
ArMonitors = new JLabel[11];
ArMonitors[1] = Monitor1;
ArMonitors[2] = Monitor2;
ArMonitors[3] = Monitor3;
ArMonitors[4] = Monitor4;
ArMonitors[5] = Monitor5;
ArMonitors[6] = Monitor6;
ArMonitors[7] = Monitor7;
ArMonitors[8] = Monitor8;
ArMonitors[9] = Monitor9;
ArMonitors[10] = Monitor10;
GraphicsEnvironment ge = GraphicsEnvironment.
getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
System.out.println(gs.length);
for (int i=1; i <= gs.length; i++){
ArMonitors[i].setVisible(true);
}
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
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.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
}
});
MainFrame mainfr = new MainFrame();
mainfr.InititalMonitorsDetection();
mainfr.DetectMonitors();<code>`
ありがとうございました。 – vizalerd