java - How to apply JTatto themes on JFrame using Swing -
i trying apply jtatto , feel in swing project.
the theme being applied on forms on others controls aren't working properly. overlapping on top of each other.
to apply theme using following code
try { string lookandfeel="com.jtattoo.plaf.smart.smartlookandfeel"; uimanager.setlookandfeel(lookandfeel); } catch(exception ex) { ex.printstacktrace(); }
works expecting
l&f must be
initialized before gui creations
for changes on runtime, applied top-level containers calling swingutilities.updatecomponenttreeui(component c), simpler
component c
== local variabletop-level container
, otherwise have iterating , apply each of jcomponents separatelly, in current components tree
import java.awt.borderlayout; import java.awt.dimension; import java.awt.event.actionevent; import javax.swing.abstractaction; import javax.swing.icon; import javax.swing.jframe; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.jmenuitem; import javax.swing.jpanel; import javax.swing.jtextpane; import javax.swing.swingutilities; import javax.swing.uimanager; import javax.swing.border.bevelborder; public class menuexample extends jpanel { private static final long serialversionuid = 1l; private icon erroricon = uimanager.geticon("optionpane.erroricon"); private icon infoicon = uimanager.geticon("optionpane.informationicon"); private icon warnicon = uimanager.geticon("optionpane.warningicon"); private icon questicon = uimanager.geticon("optionpane.questionicon"); private jtextpane pane; private jmenubar menubar; public menuexample() { menubar = new jmenubar(); jmenu formatmenu = new jmenu("justify"); formatmenu.setmnemonic('j'); menuaction leftjustifyaction = new menuaction("left", erroricon); menuaction rightjustifyaction = new menuaction("right", infoicon); menuaction centerjustifyaction = new menuaction("center", warnicon); menuaction fulljustifyaction = new menuaction("full", questicon); jmenuitem item; item = formatmenu.add(leftjustifyaction); item.setmnemonic('l'); item = formatmenu.add(rightjustifyaction); item.setmnemonic('r'); item = formatmenu.add(centerjustifyaction); item.setmnemonic('c'); item = formatmenu.add(fulljustifyaction); item.setmnemonic('f'); menubar.add(formatmenu); menubar.setborder(new bevelborder(bevelborder.raised)); pane = new jtextpane(); pane.setpreferredsize(new dimension(250, 250)); pane.setborder(new bevelborder(bevelborder.lowered)); jframe frame = new jframe("menu example"); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setjmenubar(menubar); frame.add(pane, borderlayout.center); frame.pack(); frame.setlocation(150, 150); frame.setvisible(true); } class menuaction extends abstractaction { public menuaction(string text, icon icon) { super(text, icon); } @override public void actionperformed(actionevent e) { try { pane.getstyleddocument().insertstring(0, "action [" + e.getactioncommand() + "] performed!\n", null); } catch (exception ex) { ex.printstacktrace(); } } } public static void main(string s[]) { try { uimanager.setlookandfeel("com.jtattoo.plaf.smart.smartlookandfeel"); } catch (exception ex) { ex.printstacktrace(); } swingutilities.invokelater(new runnable() { @override public void run() { menuexample example = new menuexample(); } }); } }
Comments
Post a Comment