2017-05-14 38 views

回答

0

你可以在不同的地方实现它。其中一种方法是构造函数,例如:

public YourClassPanel() { 
// to set Look&Feel  
      try { 
       UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); 
      } catch (ClassNotFoundException ex) { 
       Logger.getLogger(ControlPanel.class.getName()).log(Level.SEVERE, null, ex); 
      } catch (InstantiationException ex) { 
       Logger.getLogger(ControlPanel.class.getName()).log(Level.SEVERE, null, ex); 
      } catch (IllegalAccessException ex) { 
       Logger.getLogger(ControlPanel.class.getName()).log(Level.SEVERE, null, ex); 
      } catch (UnsupportedLookAndFeelException ex) { 
       Logger.getLogger(ControlPanel.class.getName()).log(Level.SEVERE, null, ex); 
      } 
      SwingUtilities.updateComponentTreeUI(this); 
      this.addWindowListener(new WindowAdapter() { 
       @Override 
       public void windowClosing(WindowEvent e) { 
        ControlPanel.tgp = null; 
       } 
      }); 

      this.setBounds(0, 0, 710, 580); 
      this.setTitle("Buffer Allocation Panel"); 
      this.setPreferredSize(null); 
      this.setResizable(false); 

    this.setBackground(Color.yellow); //to set Background 
    this.setForeground(Color.magenta); // to set Foreground 
    this.setOpaque(a!=255); // to set Opaque 

     } 
0

Properties中为JPanel背景设置不同的颜色。

+0

我是一个Java初学者 –

+0

你能解释一下吗? –

相关问题