1 package hudson.jnlp; 2 3 import javax.swing.UIManager ; 4 import javax.swing.UnsupportedLookAndFeelException ; 5 import javax.swing.JPanel ; 6 import javax.swing.JComponent ; 7 import javax.swing.Icon ; 8 import javax.swing.JLabel ; 9 import java.awt.GridBagConstraints ; 10 import java.awt.GridBagLayout ; 11 import java.awt.Dimension ; 12 13 17 public class GUI { 18 23 public static void setUILookAndFeel() { 24 try { 25 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 26 } catch (InstantiationException e) { 27 } catch (ClassNotFoundException e) { 28 } catch (UnsupportedLookAndFeelException e) { 29 } catch (IllegalAccessException e) { 30 } 31 } 32 33 private static final GridBagConstraints gbc; 36 37 static { 38 gbc = new GridBagConstraints (); 39 gbc.gridx = 0; 40 gbc.gridy = 0; 41 gbc.weightx = 1.0; 42 gbc.weighty = 1.0; 43 gbc.fill = GridBagConstraints.BOTH; 44 gbc.anchor = GridBagConstraints.NORTHWEST; 45 } 46 47 public static JPanel wrapInBackgroundImage(JComponent component, 48 Icon backgroundIcon, 49 int verticalAlignment, 50 int horizontalAlignment) { 51 52 component.setOpaque(false); 54 55 JPanel backgroundPanel = new JPanel (new GridBagLayout ()); 57 58 backgroundPanel.add(component, gbc); 60 61 JLabel backgroundImage = new JLabel (backgroundIcon); 63 64 backgroundImage.setPreferredSize(new Dimension (1,1)); 67 backgroundImage.setMinimumSize(new Dimension (1,1)); 68 69 backgroundImage.setVerticalAlignment(verticalAlignment); 71 backgroundImage.setHorizontalAlignment(horizontalAlignment); 72 73 backgroundPanel.add(backgroundImage, gbc); 75 76 return backgroundPanel; 78 } 79 } 80 | Popular Tags |