KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > snow > utils > gui > GUIUtils


1 package snow.utils.gui;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import javax.swing.*;
6
7 public class GUIUtils extends JDialog
8 {
9
10   public static JPanel wrapLeft(Component c)
11   {
12     JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
13     p.setOpaque(false);
14     p.add(c);
15     return p;
16   }
17
18   public static JPanel wrapRight(Component c)
19   {
20     JPanel p = new JPanel(new FlowLayout(FlowLayout.RIGHT,0,0));
21     p.setOpaque(false);
22     p.add(c);
23     return p;
24   }
25
26   /**
27     small borders especially for buttons
28   */

29   public static void setNarrowInsets(JComponent b)
30   {
31     int fs = b.getFont().getSize();
32     if(b instanceof JButton)
33     {
34       ((JButton) b).setMargin(new Insets(fs/8,fs/4,fs/8,fs/4));
35     }
36     else if(b instanceof JToggleButton)
37     {
38       ((JToggleButton) b).setMargin(new Insets(fs/8,fs/4,fs/8,fs/4));
39     }
40     else
41     {
42       //### NOT WORKING !!!
43
b.getInsets().set(fs/8,fs/4,fs/8,fs/4);
44     }
45   }
46    /*
47   public static void setMediumInsets(JButton b)
48   {
49     int fs = b.getFont().getSize();
50     b.setMargin(new Insets(fs/8,fs/2,fs/8,fs/2));
51   } */

52
53   /** small insets + small dim.
54   * TODO: not nice when setting text
55   */

56   public static void setSmallDimensions(JComponent button)
57   {
58
59
60    /* if(button instanceof JButton)
61     {
62        JButton b = (JButton) button;
63        b.setMargin(null);
64     }
65     else*/

66     {
67        setNarrowInsets(button);
68        button.invalidate();
69        //button.setPreferredSize(button.getPreferredSize());
70
button.setPreferredSize(new Dimension(
71           (int) button.getPreferredSize().getWidth(),
72           button.getFont().getSize()*8/4
73        ));
74     }
75   }
76
77 } // GUIUtils
Popular Tags