1
Is there any way to change the color of background and foreground from the java menu bar?
I searched several forums and tutorials and could not find a way to change the menu bar color.
Following example:
public class menu extends javax.swing.JFrame {
public menu() {
initComponents();
jMenuBar2.setBackground(Color.BLACK);
jMenuBar2.setForeground(Color.WHITE);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jMenuBar2 = new javax.swing.JMenuBar();
jMenu3 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jMenuItem5 = new javax.swing.JMenuItem();
jMenuItem6 = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
jMenuItem7 = new javax.swing.JMenuItem();
jMenuItem8 = new javax.swing.JMenuItem();
jMenuItem9 = new javax.swing.JMenuItem();
jMenuItem10 = new javax.swing.JMenuItem();
jMenuItem11 = new javax.swing.JMenuItem();
jMenuItem12 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jMenu3.setText("File");
jMenuItem1.setText("jMenuItem1");
jMenu3.add(jMenuItem1);
jMenuItem2.setText("jMenuItem1");
jMenu3.add(jMenuItem2);
jMenuItem3.setText("jMenuItem1");
jMenu3.add(jMenuItem3);
jMenuItem4.setText("jMenuItem1");
jMenu3.add(jMenuItem4);
jMenuItem5.setText("jMenuItem1");
jMenu3.add(jMenuItem5);
jMenuItem6.setText("jMenuItem1");
jMenu3.add(jMenuItem6);
jMenuBar2.add(jMenu3);
jMenu4.setText("Edit");
jMenuItem7.setText("jMenuItem7");
jMenu4.add(jMenuItem7);
jMenuItem8.setText("jMenuItem7");
jMenu4.add(jMenuItem8);
jMenuItem9.setText("jMenuItem7");
jMenu4.add(jMenuItem9);
jMenuItem10.setText("jMenuItem7");
jMenu4.add(jMenuItem10);
jMenuItem11.setText("jMenuItem7");
jMenu4.add(jMenuItem11);
jMenuItem12.setText("jMenuItem7");
jMenu4.add(jMenuItem12);
jMenuBar2.add(jMenu4);
setJMenuBar(jMenuBar2);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 548, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 376, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
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(menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(menu.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 menu().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar2;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem10;
private javax.swing.JMenuItem jMenuItem11;
private javax.swing.JMenuItem jMenuItem12;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenuItem jMenuItem5;
private javax.swing.JMenuItem jMenuItem6;
private javax.swing.JMenuItem jMenuItem7;
private javax.swing.JMenuItem jMenuItem8;
private javax.swing.JMenuItem jMenuItem9;
// End of variables declaration
}
Depends, which LAF you are using?
– user28595
I’m using the LAF Nimbus.
– Ulisses Gimenes
Just change the color of the slider, will not touch the colors of the items with and without non ne selection?
– user28595
I would like to put it black, with the white foreground the items in the same way, when I apply the methods nothing happens, I would like to highlight the selection of the item and the selected menu..
– Ulisses Gimenes
And when the items are selected?
– user28595
I would like to change so that it is compatible with the color of the bar type a gray in the selected item with the color of the font in black, I do not know if it is possible..
– Ulisses Gimenes
Black background with gray selection?
– user28595
Yeah, that’s the way it is...
– Ulisses Gimenes
I’ll give you a heads-up, this is a lot of work to do, and you’re going to miss out on some of the appearance of Nemos, like the gradients. The least laborious way to do this is by removing the appearance of Nimbus and changing the opacity, but it will look like those menus in windows 98. It makes a difference to you?
– user28595
I’d need to see this one less laborious to get an idea. Veses don’t pay off..
– Ulisses Gimenes
Hold on I’ll post an example using your code.
– user28595