java - How do I put the JMenuBar on top in mac and change the background of a JButton -
i building mac desktop application in java. want change background of jbutton , want make jmenubar in top.
to put jmenubar on top added code:
system.setproperty("apple.laf.usescreenmenubar", "true"); system.setproperty( "com.apple.mrj.application.apple.menu.about.name", "stack");
and worked!
and change backgroud color used this:
jbutton b = new jbutton("press me!"); b.setbackground(color.blue); b.setcontentareafilled(false); b.setopaque(true); b.setborderpainted(true); try { uimanager.setlookandfeel(uimanager .getcrossplatformlookandfeelclassname()); } catch (exception e) { }
and worked!
the problem when changed color jmenubar not in top. after little debugging know changing lookandfeel responsable.
the complete code:
import java.awt.color; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.uimanager; public class main { public static void main(string[] args) { system.setproperty("apple.laf.usescreenmenubar", "true"); system.setproperty( "com.apple.mrj.application.apple.menu.about.name", "stack"); jbutton b = new jbutton("press me!"); b.setbackground(color.blue); b.setcontentareafilled(false); b.setopaque(true); b.setborderpainted(true); try { uimanager.setlookandfeel(uimanager .getcrossplatformlookandfeelclassname()); } catch (exception e) { } jframe f = new jframe(); f.add(b); jmenubar m = new jmenubar(); m.add(new jmenu("item")); f.setjmenubar(m); f.setvisible(true); f.setvisible(true); } }
so code change color of button jmenubar not in top. if comment lines in try not change color put jmenubar on top.
any help??
thanks in advance!
i solved adding line
b.setui(new metalbuttonui());
and deleting try catch.
it ended looking these:
import java.awt.color; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.uimanager; import javax.swing.plaf.metal.metalbuttonui; public class main { public static void main(string[] args) { system.setproperty("apple.laf.usescreenmenubar", "true"); system.setproperty("com.apple.mrj.application.apple.menu.about.name", "stack"); jbutton b = new jbutton("press me!"); b.setbackground(color.blue); b.setcontentareafilled(false); b.setopaque(true); b.setborderpainted(true); b.setui(new metalbuttonui()); jframe f = new jframe(); f.add(b); f.setbounds(0, 0, 500, 500); jmenubar m = new jmenubar(); m.add(new jmenu("item")); f.setjmenubar(m); f.setvisible(true); f.setvisible(true); } }
Comments
Post a Comment