Example usage for javax.swing SwingConstants RIGHT

List of usage examples for javax.swing SwingConstants RIGHT

Introduction

In this page you can find the example usage for javax.swing SwingConstants RIGHT.

Prototype

int RIGHT

To view the source code for javax.swing SwingConstants RIGHT.

Click Source Link

Document

Box-orientation constant used to specify the right side of a box.

Usage

From source file:Main.java

public static JLabel newJLabel(String label) {
    JLabel ret = new JLabel(label);
    ret.setHorizontalAlignment(SwingConstants.RIGHT);
    return ret;/*from www  .  ja  v a  2  s  .c  o  m*/
}

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;//  w  ww  .jav a2  s.  c  om
}

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;
        }//  w w  w  .j  a v  a 2 s. c  o m
    }
    return swingAlign;
}

From source file:Main.java

/**
 * Initializes a default margin in provided directions.
 * <p>/*from ww w  . j  av  a  2 s  .  c  o m*/
 * 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:Main.java

/**
 * Creates a JLabel which text is right aligned.
 * //from  w w w  . j a  v a2s  .  co m
 * @param aText
 *          the text of the JLabel to create, may be <code>null</code>.
 * @return a JLabel instance, never <code>null</code>.
 */
public static final JLabel createRightAlignedLabel(final String aText) {
    final JLabel label = new JLabel(aText);
    label.setHorizontalAlignment(SwingConstants.RIGHT);
    return label;
}

From source file:Main.java

public static void setFont(JComponent component, Font font, ComponentOrientation componentOrientation) {
    component.setFont(font);//from w  w w. ja v  a 2 s . co m

    if (component instanceof JTextField) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JTextArea) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JTextPane) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JScrollPane) {
        for (Component cmp : component.getComponents()) {
            setFont((JComponent) cmp, font, componentOrientation);
        }
    }

    if (component instanceof JTree) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JComboBox) {
        component.setComponentOrientation(componentOrientation);
        JComboBox comboBox = (JComboBox) component;
        ((BasicComboBoxRenderer) comboBox.getRenderer()).setHorizontalAlignment(SwingConstants.RIGHT);
        ((BasicComboBoxRenderer) comboBox.getRenderer()).setAutoscrolls(true);
        comboBox.setMaximumRowCount(20);
    }

    /* if(component instanceof JLabel) {
     ((JLabel)component).setHorizontalTextPosition(SwingConstants.RIGHT);
     }*/

    if (component instanceof JPanel) {
        JPanel panel = (JPanel) component;
        if (panel.getBorder() != null && panel.getBorder() instanceof TitledBorder) {
            ((TitledBorder) panel.getBorder()).setTitleFont(font);
            panel.setComponentOrientation(componentOrientation);
        }
        for (Component cmp : component.getComponents()) {
            setFont((JComponent) cmp, font, componentOrientation);
        }
    }

    if (component instanceof JTabbedPane) {
        JTabbedPane tabbedPane = (JTabbedPane) component;
        int tabCount = tabbedPane.getTabCount();
        for (int i = 0; i < tabCount; i++) {
            setFont((JComponent) tabbedPane.getComponentAt(i), font, componentOrientation);
        }
    }
}

From source file:Main.java

public Main() {
    super("JLabel Demo");
    setSize(600, 100);//from w  ww.jav a  2  s.  c  o  m

    JPanel content = new JPanel(new GridLayout(1, 4, 4, 4));

    JLabel label = new JLabel("Java2s");
    label.setBackground(Color.white);
    content.add(label);

    label = new JLabel("Java2s", SwingConstants.CENTER);
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    label = new JLabel("Java2s");
    label.setFont(new Font("Helvetica", Font.BOLD, 18));
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    ImageIcon image = new ImageIcon("java2sLogo.gif");
    label = new JLabel("Java2s", image, SwingConstants.RIGHT);
    label.setVerticalTextPosition(SwingConstants.TOP);
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    getContentPane().add(content);
    setVisible(true);
}

From source file:LabelDemo.java

public LabelDemo() {
    super("JLabel Demo");
    setSize(600, 100);/* www  . ja v a  2s  .  c o  m*/

    JPanel content = new JPanel(new GridLayout(1, 4, 4, 4));

    JLabel label = new JLabel("Java2s");
    label.setBackground(Color.white);
    content.add(label);

    label = new JLabel("Java2s", SwingConstants.CENTER);
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    label = new JLabel("Java2s");
    label.setFont(new Font("Helvetica", Font.BOLD, 18));
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    ImageIcon image = new ImageIcon("java2sLogo.gif");
    label = new JLabel("Java2s", image, SwingConstants.RIGHT);
    label.setVerticalTextPosition(SwingConstants.TOP);
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    getContentPane().add(content);
    setVisible(true);
}

From source file:com.mgmtp.perfload.loadprofiles.ui.component.IntegerCellEditor.java

public IntegerCellEditor() {
    super(new JFormattedTextField());
    ((JTextField) getComponent()).setHorizontalAlignment(SwingConstants.RIGHT);
}

From source file:CascadeDemo.java

public CascadeDemo() {
    super("CascadeDemo");
    EARTH = new ImageIcon("earth.jpg");
    m_count = m_tencount = 0;/*from  w w w  . j  a  v a  2s  .c o m*/

    m_desktop = new JDesktopPane();
    m_desktop.putClientProperty("JDesktopPane.dragMode", "outline");
    m_newFrame = new JButton("New Frame");
    m_newFrame.addActionListener(this);

    m_infos = UIManager.getInstalledLookAndFeels();
    String[] LAFNames = new String[m_infos.length];
    for (int i = 0; i < m_infos.length; i++) {
        LAFNames[i] = m_infos[i].getName();
    }
    m_UIBox = new JComboBox(LAFNames);
    m_UIBox.addActionListener(this);

    JPanel topPanel = new JPanel(true);
    topPanel.add(m_newFrame);
    topPanel.add(new JLabel("Look & Feel:", SwingConstants.RIGHT));
    topPanel.add(m_UIBox);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add("North", topPanel);
    getContentPane().add("Center", m_desktop);

    setSize(570, 400);
    Dimension dim = getToolkit().getScreenSize();
    setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2);
    setVisible(true);
    WindowListener l = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(l);
}