Display frames, or better known as the "Look and Feel" in java can be adjusted according to our wishes. Java have three basic Look and Feel of Metal, Motif and Windows. In addition, many available Look and Feel on the Internet that can be downloaded for free. Here are examples of programs that adjust the look or theme and frame.
And here are examples of how it looks:
And here are examples of how it looks:
Here is the full program :
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class LookAndFeelDemo extends JFrame { private final String lookName[] = {"Metal", "Motif", "Windows"}; private UIManager.LookAndFeelInfo looks[]; private JRadioButton rdLook[]; private ButtonGroup btnGroup; private JButton btn; private JTextField txt; private JPanel panel1, panel2; public LookAndFeelDemo () { super ("Look and Feel Demo : Tampilan Frame"); setSize (400,300); Container container = getContentPane(); ItemHandler handler = new ItemHandler (); panel1 = new JPanel(); panel2 = new JPanel(); btnGroup = new ButtonGroup(); rdLook = new JRadioButton [lookName.length]; for (int i = 0; i < rdLook.length; i++) { rdLook[i] = new JRadioButton (lookName[i]); rdLook[i].addItemListener(handler); btnGroup.add(rdLook[i]); panel2.add(rdLook[i]); } btn = new JButton ("Tombol"); txt = new JTextField (20); panel1.add(btn); panel1.add(txt); container.add(panel1, BorderLayout.NORTH); container.add(panel2, BorderLayout.SOUTH); looks = UIManager.getInstalledLookAndFeels(); setLocationRelativeTo (null); setVisible (true); } private void changeLookAndFeel(int val) { try { UIManager.setLookAndFeel(looks[val].getClassName()); SwingUtilities.updateComponentTreeUI(this); } catch (Exception ex) { ex.printStackTrace(); } } public static void main (String args[]) { LookAndFeelDemo test = new LookAndFeelDemo(); test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private class ItemHandler implements ItemListener { public void itemStateChanged (ItemEvent e) { // for (int i = 0; i < rdLook.length; i++) { if (rdLook[i].isSelected()) { changeLookAndFeel (i); } } } } }
0 comments on Example Program Setting Frame Display With Java :
Post a Comment and Don't Spam!
Dont Spam please