Example usage for javax.swing JRadioButtonMenuItem setHorizontalTextPosition

List of usage examples for javax.swing JRadioButtonMenuItem setHorizontalTextPosition

Introduction

In this page you can find the example usage for javax.swing JRadioButtonMenuItem setHorizontalTextPosition.

Prototype

@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.LEFT", "SwingConstants.CENTER",
        "SwingConstants.RIGHT", "SwingConstants.LEADING",
        "SwingConstants.TRAILING" }, description = "The horizontal position of the text relative to the icon.")
public void setHorizontalTextPosition(int textPosition) 

Source Link

Document

Sets the horizontal position of the text relative to the icon.

Usage

From source file:Main.java

public Main() {
    menuBar = new JMenuBar();
    JMenu justifyMenu = new JMenu("Justify");
    ActionListener actionPrinter = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                pane.getStyledDocument().insertString(0, "Action [" + e.getActionCommand() + "] performed!\n",
                        null);/*  ww w. ja  v a 2s  .c  o m*/
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
    JRadioButtonMenuItem leftJustify = new JRadioButtonMenuItem("Left", new ImageIcon("1.gif"));
    leftJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    leftJustify
            .setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    leftJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem rightJustify = new JRadioButtonMenuItem("Right", new ImageIcon("2.gif"));
    rightJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    rightJustify
            .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    rightJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem centerJustify = new JRadioButtonMenuItem("Center", new ImageIcon("3.gif"));
    centerJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    centerJustify
            .setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    centerJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem fullJustify = new JRadioButtonMenuItem("Full", new ImageIcon("4.gif"));
    fullJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    fullJustify
            .setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fullJustify.addActionListener(actionPrinter);

    ButtonGroup group = new ButtonGroup();
    group.add(leftJustify);
    group.add(rightJustify);
    group.add(centerJustify);
    group.add(fullJustify);

    justifyMenu.add(leftJustify);
    justifyMenu.add(rightJustify);
    justifyMenu.add(centerJustify);
    justifyMenu.add(fullJustify);

    menuBar.add(justifyMenu);
    menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
}

From source file:RadioButtonMenuItemExample.java

public RadioButtonMenuItemExample() {
    menuBar = new JMenuBar();
    JMenu justifyMenu = new JMenu("Justify");
    ActionListener actionPrinter = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                pane.getStyledDocument().insertString(0, "Action [" + e.getActionCommand() + "] performed!\n",
                        null);//from  w  w w.  j a  v a 2s  .c  o m
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
    JRadioButtonMenuItem leftJustify = new JRadioButtonMenuItem("Left", new ImageIcon("1.gif"));
    leftJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    leftJustify
            .setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    leftJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem rightJustify = new JRadioButtonMenuItem("Right", new ImageIcon("2.gif"));
    rightJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    rightJustify
            .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    rightJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem centerJustify = new JRadioButtonMenuItem("Center", new ImageIcon("3.gif"));
    centerJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    centerJustify
            .setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    centerJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem fullJustify = new JRadioButtonMenuItem("Full", new ImageIcon("4.gif"));
    fullJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    fullJustify
            .setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fullJustify.addActionListener(actionPrinter);

    ButtonGroup group = new ButtonGroup();
    group.add(leftJustify);
    group.add(rightJustify);
    group.add(centerJustify);
    group.add(fullJustify);

    justifyMenu.add(leftJustify);
    justifyMenu.add(rightJustify);
    justifyMenu.add(centerJustify);
    justifyMenu.add(fullJustify);

    menuBar.add(justifyMenu);
    menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
}