En fait, j'essaie de faire une fenêtre "Setting" pour un jeu et je veux définir la couleur d'arrière-plan d'une autre fenêtre. Je n'ai aucune idée de ce qu'il faut faire. Quelques idées pls?Comment puis-je définir la couleur backgorund pour un JFrame en utilisant un JComboBox d'un autre JFrame?
0
A
Répondre
0
Vous pouvez l'implémenter à différents endroits. L'un des moyens est constructeur, par exemple:
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
Définissez une couleur différente pour JPanel
arrière-plan de Properties
.
+0
Je suis un débutant en Java –
+0
Pourriez-vous expliquer mieux? –
double possible de [Comment afficher la couleur sélectionnée dans la zone de liste déroulante] (http://stackoverflow.com/questions/15995375/how-to-display- la-color-selected-in-my-combo-box) –