Presentation is loading. Please wait.

Presentation is loading. Please wait.

“Look and Feel” and Layouts Feb 11, 2000. Pluggable Look and Feel zYou can change the looking or “look and feel” of your Swing application easily into:

Similar presentations


Presentation on theme: "“Look and Feel” and Layouts Feb 11, 2000. Pluggable Look and Feel zYou can change the looking or “look and feel” of your Swing application easily into:"— Presentation transcript:

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

2 Pluggable Look and Feel zYou can change the looking or “look and feel” of your Swing application easily into: yWindows yMacintosh yMotif (X-windows) yJava look zBig win for software portability in a sense that we can have a program which looks the same across platforms. zIf you don’t care about how your program looks, Don’t bother!!!

3 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" Setting Look and Feel

4 Layouts

5 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(); } 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); }

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"); }


Download ppt "“Look and Feel” and Layouts Feb 11, 2000. Pluggable Look and Feel zYou can change the looking or “look and feel” of your Swing application easily into:"

Similar presentations


Ads by Google