List of usage examples for javax.swing JLabel setHorizontalAlignment
@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.LEFT", "SwingConstants.CENTER", "SwingConstants.RIGHT", "SwingConstants.LEADING", "SwingConstants.TRAILING" }, description = "The alignment of the label's content along the X axis.") public void setHorizontalAlignment(int alignment)
From source file:Main.java
public static void main(String[] args) { JLabel label = new JLabel("java2s.com", JLabel.LEFT); label.setHorizontalAlignment(JLabel.CENTER); label.setVerticalAlignment(JLabel.CENTER); //label.setHorizontalAlignment(JLabel.LEFT); //label.setVerticalAlignment(JLabel.TOP); //label.setHorizontalAlignment(JLabel.RIGHT); //label.setVerticalAlignment(JLabel.BOTTOM); JOptionPane.showMessageDialog(null, label); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border emptyBorder = new EmptyBorder(5, 10, 5, 10); JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(emptyBorder);// w w w. j a va2 s. c o m aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:EtchedBorderSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, Color.RED, Color.PINK); JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(etchedBorder);// w w w.j ava 2s. c om aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:BevelBorderWithDiffBorderColor.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border bevelBorder = new BevelBorder(BevelBorder.RAISED, Color.RED, Color.RED.darker(), Color.PINK, Color.PINK.brighter()); JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(bevelBorder);//from w ww .j a va 2 s.c o m aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:MatteBorderSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Icon diamondIcon = new ImageIcon("yourImage.gif"); Border matteBorder = new MatteBorder(5, 10, 5, 10, diamondIcon); JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(matteBorder);//w w w.jav a2 s . co m aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border softBevelBorder = new SoftBevelBorder(BevelBorder.RAISED, Color.RED, Color.RED.darker(), Color.PINK, Color.PINK.brighter()); JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(softBevelBorder);/*w ww .j ava 2 s . com*/ aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel statusBar = new JPanel(new FlowLayout(FlowLayout.LEFT)); statusBar.setBorder(new CompoundBorder(new LineBorder(Color.DARK_GRAY), new EmptyBorder(4, 4, 4, 4))); final JLabel status = new JLabel(); statusBar.add(status);//from w w w . j av a 2 s.c om JLabel content = new JLabel("Content in the middle"); content.setHorizontalAlignment(JLabel.CENTER); final JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(content); frame.add(statusBar, BorderLayout.SOUTH); frame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { status.setText(frame.getWidth() + "x" + frame.getHeight()); } }); frame.setBounds(20, 20, 200, 200); frame.setVisible(true); }
From source file:ChangingTitleBorderDirection.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border lineBorder = new LineBorder(Color.RED, 5); Font font = new Font("Serif", Font.ITALIC, 12); Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM, font, Color.RED);// w w w .ja v a2 s. com JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(titledBorder); aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JLabel label = new JLabel("Label with image in Tooltip!"); label.setToolTipText("<html><img src=\"" + Main.class.getResource("tooltip.gif") + "\"> Tooltip "); label.setHorizontalAlignment(JLabel.CENTER); frame.setContentPane(label);/*from w w w. j a v a 2s. c om*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(100, 100, 200, 100); frame.setVisible(true); }
From source file:Main.java
License:asdf
public static void main(String args[]) { JFrame f = new JFrame("Label Demo"); f.setLayout(new FlowLayout()); f.setSize(200, 360);//from w w w . j a va2s . com f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("asdf"); Border border = BorderFactory.createLineBorder(Color.BLACK); label.setBorder(border); label.setPreferredSize(new Dimension(150, 100)); label.setText("Centered"); label.setHorizontalAlignment(JLabel.CENTER); label.setVerticalAlignment(JLabel.CENTER); f.add(label); f.setVisible(true); }