List of usage examples for javax.swing SwingConstants LEFT
int LEFT
To view the source code for javax.swing SwingConstants LEFT.
Click Source Link
From source file:Main.java
public static void main(final String args[]) { JButton button = new JButton("Test"); button.setHorizontalTextPosition(SwingConstants.LEFT); button.setIcon(new ImageIcon("r.gif")); button.setRolloverIcon(new ImageIcon("b.gif")); button.setRolloverEnabled(true);/* www. j a v a 2s . co m*/ JOptionPane.showMessageDialog(null, button); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); System.out.println(jb.getHorizontalAlignment() == SwingConstants.LEFT); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb);// ww w . j a v a 2s . co m f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JLabel label1 = new JLabel("BottomRight", SwingConstants.RIGHT); JLabel label2 = new JLabel("CenterLeft", SwingConstants.LEFT); JLabel label3 = new JLabel("TopCenter", SwingConstants.CENTER); label1.setVerticalAlignment(SwingConstants.BOTTOM); label2.setVerticalAlignment(SwingConstants.CENTER); label3.setVerticalAlignment(SwingConstants.TOP); label1.setBorder(BorderFactory.createLineBorder(Color.black)); label2.setBorder(BorderFactory.createLineBorder(Color.black)); label3.setBorder(BorderFactory.createLineBorder(Color.black)); JFrame frame = new JFrame("AlignmentExample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(new GridLayout(3, 1, 8, 8)); p.add(label1);// www . java 2 s . com p.add(label2); p.add(label3); p.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); frame.setContentPane(p); frame.setSize(200, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.java2s.com/style/download.png"); BufferedImage origImg = ImageIO.read(url); JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(origImg))); File newFile = new File("new.png"); ImageIO.write(origImg, "png", newFile); BufferedImage newImg = ImageIO.read(newFile); JOptionPane.showMessageDialog(null, new JLabel("New", new ImageIcon(newImg), SwingConstants.LEFT)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton button = new JButton(); // Place text over center of icon; they both occupy the same space button.setVerticalTextPosition(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.CENTER); // Place text above icon button.setVerticalTextPosition(SwingConstants.TOP); button.setHorizontalTextPosition(SwingConstants.CENTER); // Place text below icon button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setHorizontalTextPosition(SwingConstants.CENTER); // Place text to the left of icon, vertically centered button.setVerticalTextPosition(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.LEFT); // Place text to the left of icon and align their tops button.setVerticalTextPosition(SwingConstants.TOP); button.setHorizontalTextPosition(SwingConstants.LEFT); // Place text to the left of icon and align their bottoms button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setHorizontalTextPosition(SwingConstants.LEFT); // Place text to the right of icon, vertically centered button.setVerticalTextPosition(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.RIGHT); // Place text to the right of icon and align their tops button.setVerticalTextPosition(SwingConstants.TOP); button.setHorizontalTextPosition(SwingConstants.RIGHT); // Place text to the right of icon and align their bottoms button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setHorizontalTextPosition(SwingConstants.RIGHT); }
From source file:Main.java
public static int asHAlign(String val) { if (val.equals("leading")) return SwingConstants.LEADING; else if (val.equals("trailing")) return SwingConstants.TRAILING; else if (val.equals("left")) return SwingConstants.LEFT; else if (val.equals("right")) return SwingConstants.RIGHT; else if (val.equals("center")) return SwingConstants.CENTER; assert false; return -1;/*from w w w .j a v a 2s . c o m*/ }
From source file:Main.java
public static JPanel createTextComponentPane(String labelText, JTextComponent textComp, Font font, Color bgColor, boolean isVertical) { JPanel outPane = new JPanel(); outPane.setLayout(new BorderLayout()); outPane.setBorder(new EmptyBorder(5, 5, 5, 5)); JLabel labelOut = new JLabel(labelText, SwingConstants.LEFT); if (isVertical) { outPane.add(labelOut, BorderLayout.NORTH); } else {/* www .ja v a 2s . co m*/ outPane.add(labelOut, BorderLayout.WEST); } if (textComp instanceof JTextArea) { outPane.add(createScrollPane((JTextArea) textComp, font, bgColor), BorderLayout.CENTER); } else { textComp.setBackground(bgColor); textComp.setFont(font); outPane.add(textComp, BorderLayout.CENTER); } return outPane; }
From source file:Main.java
private static int createDefaultHorizontalAlignment() { int swingAlign = SwingConstants.RIGHT; String defaultAlignment = UIManager.getDefaults().getString("Label.defaultHorizontalAlignment"); if (defaultAlignment != null) { if ("LEFT".equalsIgnoreCase(defaultAlignment)) { swingAlign = SwingConstants.LEFT; } else if ("RIGHT".equalsIgnoreCase(defaultAlignment)) { swingAlign = SwingConstants.RIGHT; } else if ("CENTER".equalsIgnoreCase(defaultAlignment)) { swingAlign = SwingConstants.CENTER; }/*from ww w . j a v a 2s. co m*/ } return swingAlign; }
From source file:Main.java
/** * Initializes a default margin in provided directions. * <p>// w ww . j a va2 s . c om * Directions provided can be one of the TOP, LEFT, DOWN and BOTTOM * constants from the {@link SwingConstants} interface. * * @param directions Array of directions where the border is to be created. * @return Empty border to be used as margin; border width defined as * {@link #DEFAULT_MARGIN}. */ public static Border defaultMargin(int... directions) { int[] borders = new int[4]; if (directions == null) return BorderFactory.createEmptyBorder(); for (int i = 0; i < directions.length; i++) { if (directions[i] == SwingConstants.TOP) borders[0] = DEFAULT_MARGIN; if (directions[i] == SwingConstants.LEFT) borders[1] = DEFAULT_MARGIN; if (directions[i] == SwingConstants.BOTTOM) borders[2] = DEFAULT_MARGIN; if (directions[i] == SwingConstants.RIGHT) borders[3] = DEFAULT_MARGIN; } return BorderFactory.createEmptyBorder(borders[0], borders[1], borders[2], borders[3]); }
From source file:MainClass.java
MainClass(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton jb = new JButton("Ok", new ImageIcon("bullet.gif")); jb.setHorizontalAlignment(SwingConstants.LEFT); jb.setMnemonic('O'); getContentPane().add(jb, BorderLayout.CENTER); jb = new JButton("<html><i>Cancel</i></html>"); jb.setVerticalAlignment(SwingConstants.BOTTOM); jb.setDefaultCapable(true);/*from w w w.j av a 2 s. c o m*/ getContentPane().add(jb, BorderLayout.EAST); getRootPane().setDefaultButton(jb); setSize(200, 100); setVisible(true); }