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:BoxLayoutDemo.java
private static JComponent createComponent(String s) { JLabel l = new JLabel(s); l.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.DARK_GRAY)); l.setHorizontalAlignment(JLabel.CENTER); l.setAlignmentX(Component.CENTER_ALIGNMENT); //use middle of row return l;// w w w .j a v a2 s. com }
From source file:FieldValidator.java
private static JComponent createContent() { Dimension labelSize = new Dimension(80, 20); Box box = Box.createVerticalBox(); // A single LayerUI for all the fields. LayerUI<JFormattedTextField> layerUI = new ValidationLayerUI(); // Number field. JLabel numberLabel = new JLabel("Number:"); numberLabel.setHorizontalAlignment(SwingConstants.RIGHT); numberLabel.setPreferredSize(labelSize); NumberFormat numberFormat = NumberFormat.getInstance(); JFormattedTextField numberField = new JFormattedTextField(numberFormat); numberField.setColumns(16);//from w ww .ja va2 s. c o m numberField.setFocusLostBehavior(JFormattedTextField.PERSIST); numberField.setValue(42); JPanel numberPanel = new JPanel(); numberPanel.add(numberLabel); numberPanel.add(new JLayer<JFormattedTextField>(numberField, layerUI)); // Date field. JLabel dateLabel = new JLabel("Date:"); dateLabel.setHorizontalAlignment(SwingConstants.RIGHT); dateLabel.setPreferredSize(labelSize); DateFormat dateFormat = DateFormat.getDateInstance(); JFormattedTextField dateField = new JFormattedTextField(dateFormat); dateField.setColumns(16); dateField.setFocusLostBehavior(JFormattedTextField.PERSIST); dateField.setValue(new java.util.Date()); JPanel datePanel = new JPanel(); datePanel.add(dateLabel); datePanel.add(new JLayer<JFormattedTextField>(dateField, layerUI)); // Time field. JLabel timeLabel = new JLabel("Time:"); timeLabel.setHorizontalAlignment(SwingConstants.RIGHT); timeLabel.setPreferredSize(labelSize); DateFormat timeFormat = DateFormat.getTimeInstance(); JFormattedTextField timeField = new JFormattedTextField(timeFormat); timeField.setColumns(16); timeField.setFocusLostBehavior(JFormattedTextField.PERSIST); timeField.setValue(new java.util.Date()); JPanel timePanel = new JPanel(); timePanel.add(timeLabel); timePanel.add(new JLayer<JFormattedTextField>(timeField, layerUI)); // Put them all in the box. box.add(Box.createGlue()); box.add(numberPanel); box.add(Box.createGlue()); box.add(datePanel); box.add(Box.createGlue()); box.add(timePanel); return box; }
From source file:QandE.MyDemo1.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from w w w . j a va2 s . c o m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("MyDemo1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add a label with bold italic font. JLabel label = new JLabel("My Demo"); frame.getContentPane().add(BorderLayout.CENTER, label); if (true) { label.setFont(label.getFont().deriveFont(Font.ITALIC | Font.BOLD)); } else { //another way of doing it, but not as appropriate since //setFont is faster than using HTML. label.setText("<html><i>My Demo</i></html>"); } label.setHorizontalAlignment(JLabel.CENTER); //Display the window, making it a little bigger than it really needs to be. frame.pack(); frame.setSize(frame.getWidth() + 100, frame.getHeight() + 50); frame.setVisible(true); }
From source file:QandE.MyDemo3.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//ww w . j a va2 s . c om */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("MyDemo3"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add a label with bold italic font. JLabel label = new JLabel("My Demo"); frame.getContentPane().add(BorderLayout.CENTER, label); if (true) { label.setFont(label.getFont().deriveFont(Font.ITALIC | Font.BOLD)); } else { //another way of doing it, but not as appropriate since //setFont is faster than using HTML. label.setText("<html><i>My Demo</i></html>"); } label.setHorizontalAlignment(JLabel.CENTER); JButton b = new JButton("A button"); frame.getContentPane().add(BorderLayout.PAGE_END, b); frame.getRootPane().setDefaultButton(b); //Display the window, making it a little bigger than it really needs to be. frame.pack(); frame.setSize(frame.getWidth() + 100, frame.getHeight() + 50); frame.setVisible(true); }
From source file:QandE.MyDemo2.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//from w w w . jav a 2s .c o m */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("MyDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenu menu = new JMenu("Menu"); JMenuBar mb = new JMenuBar(); mb.add(menu); frame.setJMenuBar(mb); //Add a label with bold italic font. JLabel label = new JLabel("My Demo"); frame.getContentPane().add(BorderLayout.CENTER, label); if (true) { label.setFont(label.getFont().deriveFont(Font.ITALIC | Font.BOLD)); } else { //another way of doing it, but not as appropriate since //setFont is faster than using HTML. label.setText("<html><i>My Demo</i></html>"); } label.setHorizontalAlignment(JLabel.CENTER); //Display the window, making it a little bigger than it really needs to be. frame.pack(); frame.setSize(frame.getWidth() + 100, frame.getHeight() + 50); frame.setVisible(true); }
From source file:TitledExample.java
public TitledExample() { super(true);//from ww w. j av a 2s .c om this.setLayout(new GridLayout(1, 1, 5, 5)); JLabel label = new JLabel("Titled Border"); label.setHorizontalAlignment(JLabel.CENTER); TitledBorder titled = new TitledBorder("Title"); label.setBorder(titled); add(label); }
From source file:Main.java
private JLabel createLabel(String label) { JLabel jLabel = new JLabel(label); jLabel.setHorizontalAlignment(JLabel.CENTER); jLabel.setFont(jLabel.getFont().deriveFont(48.0f)); jLabel.setFocusable(true);/* w w w . j a v a2s.co m*/ return jLabel; }
From source file:RoundedLineBorder.java
public RoundedLineBorder() { super(true);//w w w . j a v a 2 s . c om setLayout(new BorderLayout()); JLabel label = new JLabel("Rounded Corners"); label.setHorizontalAlignment(JLabel.CENTER); LineBorder line = new LineBorder(Color.blue, 2, true); label.setBorder(line); add(label, BorderLayout.CENTER); }
From source file:Main.java
public Main() { GridLayout g = new GridLayout(3, 3); pan = new JPanel(g); pan.add(new JButton("1")); pan.add(new JButton("2")); pan.add(new JButton("3")); pan.add(new JButton("4")); pan.add(new JButton("5")); pan.add(new JButton("6")); pan.add(new JButton("7")); pan.add(new JButton("8")); pan.add(new JButton("9")); JLabel l = new JLabel("grid layout"); l.setHorizontalAlignment(SwingConstants.CENTER); setLayout(new BorderLayout()); add(l, BorderLayout.NORTH);//w w w.j a v a 2s . c o m add(pan, BorderLayout.CENTER); setSize(1000, 500); setVisible(true); }
From source file:AlignLabels.java
void setNWalignment(JLabel b) { b.setHorizontalAlignment(JLabel.LEFT); b.setVerticalAlignment(JLabel.TOP); }