1 / 10

“Look and Feel” and Layouts

“Look and Feel” and Layouts. Feb 11, 2000. Pluggable Look and Feel. You can change the looking or “look and feel” of your Swing application easily into: Windows Macintosh Motif (X-windows) Java look

lovie
Download Presentation

“Look and Feel” and Layouts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. “Look and Feel” and Layouts Feb 11, 2000

  2. Pluggable Look and Feel • You can change the looking or “look and feel” of your Swing application easily into: • Windows • Macintosh • Motif (X-windows) • Java look • Big win for software portability in a sense that we can have a program which looks the same across platforms. • If you don’t care about how your program looks, Don’t bother!!!

  3. Setting Look and Feel public static void main(String[] args) { try { UIManager.setLookAndFeel( // Put your favorite Look and Feel here!!! ); } catch (Exception e) { } new SwingApplication(); } • "javax.swing.plaf.metal.MetalLookAndFeel" • "com.sun.java.swing.plaf.windows.WindowsLookAndFeel” • "com.sun.java.swing.plaf.motif.MotifLookAndFeel" • "javax.swing.plaf.mac.MacLookAndFeel"

  4. Layouts

  5. private void addComponent() { // next page } public static void main(String args[]) { int w = Integer.parseInt(args[0]); int l = Integer.parseInt(args[1]); LayoutDemo demo = new LayoutDemo(); demo.setupGUI(w,l); } } import java.awt.*; import java.awt.event.*; import javax.swing.*; class LayoutDemo { JFrame frame; Container pane; LayoutDemo(){ frame = new JFrame("LayoutDemo"); pane = frame.getContentPane(); } private void setupGUI(int w,int l) { addComponent(); frame.setSize(w,l); frame.setVisible(true); frame.pack(); }

  6. private void addComponent(){ pane.setLayout(new BorderLayout()); JCheckBox jck1 = new JCheckBox("this class is easy"); JCheckBox jck2 = new JCheckBox("this class is hard"); pane.add(jck1,"East"); pane.add(jck2,"South"); JButton b1 = new JButton("no touch"); JButton b2 = new JButton("please touch"); pane.add(b1,"North"); pane.add(b2,"West"); JLabel label = new JLabel(new ImageIcon("cab.gif")); pane.add(label,"Center"); }

  7. private void addComponent(){ pane.setLayout(new GridLayout(2,3)); JCheckBox jck1 = new JCheckBox("this class is easy"); JCheckBox jck2 = new JCheckBox("this class is hard"); pane.add(jck1); pane.add(jck2); JButton b1 = new JButton("no touch"); JButton b2 = new JButton("please touch"); pane.add(b1); pane.add(b2); JLabel label = new JLabel(new ImageIcon("cab.gif")); pane.add(label); }

  8. private void addComponent(){ pane.setLayout(new FlowLayout()); JCheckBox jck1 = new JCheckBox("this class is easy"); JCheckBox jck2 = new JCheckBox("this class is hard"); pane.add(jck1); pane.add(jck2); JButton b1 = new JButton("no touch"); JButton b2 = new JButton("please touch"); pane.add(b1); pane.add(b2); JLabel label = new JLabel(new ImageIcon("cab.gif")); pane.add(label); }

  9. private void addComponent(){ pane.setLayout(new BoxLayout(pane,BoxLayout.Y_AXIS)); ... } private void addComponent(){ pane.setLayout(new BoxLayout(pane,BoxLayout.X_AXIS)); ... }

  10. private void addComponent() { JPanel p1 = new JPanel(); p1.setLayout( new BoxLayout(p1,BoxLayout.Y_AXIS)); JCheckBox jck1 = new JCheckBox("this class is easy"); JCheckBox jck2 = new JCheckBox("this class is hard"); p1.add(jck1); p1.add(jck2); JPanel p2 = new JPanel(); p2.setLayout( new BoxLayout(p2,BoxLayout.Y_AXIS)); JButton b1 = new JButton("no touch"); JButton b2 = new JButton("please touch"); p2.add(b1); p2.add(b2); JLabel label = new JLabel( new ImageIcon("cab.gif")); pane.add(label,"Center"); pane.add(p1,"West"); pane.add(p2,"East"); }

More Related