Example usage for javax.swing JButton setAlignmentX

List of usage examples for javax.swing JButton setAlignmentX

Introduction

In this page you can find the example usage for javax.swing JButton setAlignmentX.

Prototype

@BeanProperty(description = "The preferred horizontal alignment of the component.")
public void setAlignmentX(float alignmentX) 

Source Link

Document

Sets the horizontal alignment.

Usage

From source file:Main.java

public Main(int axis) {
    super(BoxLayout.Y_AXIS);
    container = new Box(axis);
    container.setAlignmentX(Box.LEFT_ALIGNMENT);
    add(container);/*from w  ww .j  ava  2s.  c om*/

    JTextArea text = new JTextArea();
    container.add(new JScrollPane(text));

    JButton split = new JButton("Split");
    split.setAlignmentX(Box.LEFT_ALIGNMENT);
    split.addActionListener(e -> {
        JTextArea t = new JTextArea();
        container.add(new JScrollPane(t));
        revalidate();
    });
    add(split);

    JButton axisChanger = new JButton("Change Axis");
    axisChanger.setAlignmentX(Box.LEFT_ALIGNMENT);
    axisChanger.addActionListener(e -> {
        Box newContainer;
        if (((BoxLayout) container.getLayout()).getAxis() == BoxLayout.X_AXIS) {
            newContainer = Box.createVerticalBox();
        } else {
            newContainer = Box.createHorizontalBox();
        }
        for (Component c : container.getComponents()) {
            container.remove(c);
            newContainer.add(c);
        }
        remove(container);
        add(newContainer, 0);
        container = newContainer;
        container.setAlignmentX(Box.LEFT_ALIGNMENT);
        revalidate();
    });
    add(axisChanger);

}

From source file:com.game.ui.views.UserDialog.java

public UserDialog(String message, JFrame frame) {
    setLayout(new BorderLayout(5, 5));
    setModalityType(ModalityType.APPLICATION_MODAL);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setResizable(false);//from ww w .jav a 2s .c om
    ImageIcon icon = null;
    try {
        icon = GameUtils.shrinkImage("warning.gif", 30, 30);
    } catch (IOException e) {
        System.out.println("Dialog : showDialogForMap(): Exception occured :" + e);
        e.printStackTrace();
    }
    JPanel panel = new JPanel();
    JLabel label = new JLabel(icon);
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    label.setText(message);
    label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    label.setHorizontalAlignment(0);
    panel.add(label);
    add(panel, BorderLayout.NORTH);
    JPanel contentPanel = new JPanel();
    contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
    txt = new JTextField();
    txt.setPreferredSize(new Dimension(150, 30));
    txt.setAlignmentX(.5f);
    txt.setMaximumSize(new Dimension(150, 30));
    contentPanel.add(txt);
    contentPanel.add(Box.createVerticalStrut(10));
    JButton btn = new JButton("Submit.");
    btn.setAlignmentX(.5f);
    btn.setPreferredSize(new Dimension(50, 25));
    btn.addActionListener(this);
    validationMess = new JLabel("All fields are mandatory");
    validationMess.setVisible(false);
    validationMess.setForeground(Color.red);
    validationMess.setAlignmentX(.5f);
    contentPanel.add(btn);
    contentPanel.add(Box.createVerticalStrut(10));
    contentPanel.add(validationMess);
    contentPanel.add(Box.createVerticalGlue());
    add(contentPanel, BorderLayout.CENTER);
    pack();
    setSize(new Dimension(300, 200));
    setLocationRelativeTo(frame);
    setVisible(true);
}

From source file:components.TablePrintDemo.java

public TablePrintDemo() {
    super();/*from w ww  .j  a va2  s. c  o m*/
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    table = new JTable(new MyTableModel());
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Add the scroll pane to this panel.
    add(scrollPane);

    //Add a print button.
    JButton printButton = new JButton("Print");
    printButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    printButton.addActionListener(this);
    add(printButton);

}

From source file:HtmlDemo.java

public HtmlDemo() {
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

    String initialText = "<html>\n" + "Color and font test:\n" + "<ul>\n" + "<li><font color=red>red</font>\n"
            + "<li><font color=blue>blue</font>\n" + "<li><font color=green>green</font>\n"
            + "<li><font size=-2>small</font>\n" + "<li><font size=+2>large</font>\n" + "<li><i>italic</i>\n"
            + "<li><b>bold</b>\n" + "</ul>\n";

    htmlTextArea = new JTextArea(10, 20);
    htmlTextArea.setText(initialText);/*from   w  w  w.  jav  a 2s.  c  o  m*/
    JScrollPane scrollPane = new JScrollPane(htmlTextArea);

    JButton changeTheLabel = new JButton("Change the label");
    changeTheLabel.setMnemonic(KeyEvent.VK_C);
    changeTheLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
    changeTheLabel.addActionListener(this);

    theLabel = new JLabel(initialText) {
        public Dimension getPreferredSize() {
            return new Dimension(200, 200);
        }

        public Dimension getMinimumSize() {
            return new Dimension(200, 200);
        }

        public Dimension getMaximumSize() {
            return new Dimension(200, 200);
        }
    };
    theLabel.setVerticalAlignment(SwingConstants.CENTER);
    theLabel.setHorizontalAlignment(SwingConstants.CENTER);

    JPanel leftPanel = new JPanel();
    leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
    leftPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Edit the HTML, then click the button"),
            BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    leftPanel.add(scrollPane);
    leftPanel.add(Box.createRigidArea(new Dimension(0, 10)));
    leftPanel.add(changeTheLabel);

    JPanel rightPanel = new JPanel();
    rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS));
    rightPanel
            .setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("A label with HTML"),
                    BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    rightPanel.add(theLabel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    add(leftPanel);
    add(Box.createRigidArea(new Dimension(10, 0)));
    add(rightPanel);
}

From source file:AboutDialog.java

public AboutDialog() {
    setTitle("About");
    setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    add(Box.createRigidArea(new Dimension(0, 10)));

    JLabel name = new JLabel("Notes");
    name.setAlignmentX(0.5f);/*  w  w  w .java2s.c o m*/
    add(name);

    add(Box.createRigidArea(new Dimension(0, 100)));

    JButton close = new JButton("Close");
    close.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            dispose();
        }
    });

    close.setAlignmentX(0.5f);
    add(close);
    setModalityType(ModalityType.APPLICATION_MODAL);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setSize(300, 200);
}

From source file:Main.java

public JPanel createUI() {
    intro.setLabelFor(name);/*from   w  w  w.  j av a  2  s .co  m*/
    final JButton button = new JButton("Pick a new name...");
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20));
    intro.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    name.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    button.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    panel.add(intro);
    panel.add(Box.createVerticalStrut(5));
    panel.add(name);
    panel.add(Box.createRigidArea(new Dimension(150, 10)));
    panel.add(button);
    return panel;
}

From source file:lisong_mechlab.view.graphs.SustainedDpsGraph.java

/**
 * Creates and displays the {@link SustainedDpsGraph}.
 * //from  w  w  w  .j  a va  2s  . c  o  m
 * @param aLoadout
 *            Which load out the diagram is for.
 * @param aXbar
 *            A {@link MessageXBar} to listen for changes to the loadout on.
 * @param aMaxSustainedDpsMetric
 *            A {@link MaxSustainedDPS} instance to use in calculation.
 */
public SustainedDpsGraph(LoadoutBase<?> aLoadout, MessageXBar aXbar, MaxSustainedDPS aMaxSustainedDpsMetric) {
    super("Max Sustained DPS over range for " + aLoadout);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    aXbar.attach(this);

    loadout = aLoadout;
    maxSustainedDPS = aMaxSustainedDpsMetric;
    chartPanel = new ChartPanel(makechart());
    setContentPane(chartPanel);

    chartPanel.setLayout(new OverlayLayout(chartPanel));
    JButton button = new JButton(
            new OpenHelp("What is this?", "Max-sustained-dps-graph", KeyStroke.getKeyStroke('w')));
    button.setMargin(new Insets(5, 5, 5, 5));
    button.setFocusable(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    button.setAlignmentY(Component.TOP_ALIGNMENT);
    chartPanel.add(button);

    setIconImage(ProgramInit.programIcon);
    setSize(800, 600);
    setVisible(true);
}

From source file:lisong_mechlab.view.graphs.DamageGraph.java

/**
 * Creates and displays the {@link DamageGraph}.
 * /* w  w w . j  a  v a2 s .  c  om*/
 * @param aLoadout
 *            Which load out the diagram is for.
 * @param anXbar
 *            A {@link MessageXBar} to listen for changes to the loadout on.
 * @param aMaxSustainedDpsMetric
 *            A {@link MaxSustainedDPS} instance to use in calculation.
 */
public DamageGraph(LoadoutBase<?> aLoadout, MessageXBar anXbar, MaxSustainedDPS aMaxSustainedDpsMetric) {
    super("Max Sustained DPS over range for " + aLoadout);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    anXbar.attach(this);

    loadout = aLoadout;
    maxSustainedDPS = aMaxSustainedDpsMetric;
    chartPanel = new ChartPanel(makechart());
    setContentPane(chartPanel);
    chartPanel.getChart().getLegend().setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chartPanel.getChart().getLegend().setVerticalAlignment(VerticalAlignment.TOP);

    LegendTitle legendTitle = chartPanel.getChart().getLegend();
    XYTitleAnnotation titleAnnotation = new XYTitleAnnotation(0.98, 0.98, legendTitle,
            RectangleAnchor.TOP_RIGHT);
    titleAnnotation.setMaxWidth(0.4);
    ((XYPlot) (chartPanel.getChart().getPlot())).addAnnotation(titleAnnotation);
    chartPanel.getChart().removeLegend();

    chartPanel.setLayout(new OverlayLayout(chartPanel));
    JButton button = new JButton(
            new OpenHelp("What is this?", "Max-sustained-dps-graph", KeyStroke.getKeyStroke('w')));
    button.setMargin(new Insets(10, 10, 10, 10));
    button.setFocusable(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    button.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    chartPanel.add(button);

    setIconImage(ProgramInit.programIcon);
    setSize(800, 600);
    setVisible(true);
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java

protected JPanel getPanel(final JDialog dialog, DefaultTableModel tModel, ArrayList<String> rowIdentifiers) {
    JPanel panel = new JPanel();
    JButton close = new JButton("Close");
    close.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);//ww w. j a  va 2  s. c  o m
        }
    });
    close.setAlignmentX(Component.CENTER_ALIGNMENT);

    RowHeaderTable table = new RowHeaderTable(tModel);
    table.getDataTable().setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.getDataTable().setDefaultRenderer(Object.class, new ColorRenderer(false));
    table.setCellsEditable(false);
    table.setHeadersEditable(false);

    for (int r = 0; r < tModel.getRowCount() && rowIdentifiers.size() <= tModel.getRowCount(); r++) {
        table.getRowHeaderModel().setValueAt(rowIdentifiers.get(r), r, 0);
    }

    Dimension d = table.getRowHeaderTable().getPreferredScrollableViewportSize();
    d.width = 55;
    table.getRowHeaderTable().setPreferredScrollableViewportSize(d);

    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.add(table);
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(close);

    return panel;
}

From source file:InternalFrameEventDemo.java

protected void createDisplayWindow() {
    JButton b1 = new JButton("Show internal frame");
    b1.setActionCommand(SHOW);/*from  w  w w. j a  va  2  s. c  o  m*/
    b1.addActionListener(this);

    JButton b2 = new JButton("Clear event info");
    b2.setActionCommand(CLEAR);
    b2.addActionListener(this);

    display = new JTextArea(3, 30);
    display.setEditable(false);
    JScrollPane textScroller = new JScrollPane(display);
    // Have to supply a preferred size, or else the scroll
    // area will try to stay as large as the text area.
    textScroller.setPreferredSize(new Dimension(200, 75));
    textScroller.setMinimumSize(new Dimension(10, 10));

    displayWindow = new JInternalFrame("Event Watcher", true, // resizable
            false, // not closable
            false, // not maximizable
            true); // iconifiable
    JPanel contentPane = new JPanel();
    contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    b1.setAlignmentX(CENTER_ALIGNMENT);
    contentPane.add(b1);
    contentPane.add(Box.createRigidArea(new Dimension(0, 5)));
    contentPane.add(textScroller);
    contentPane.add(Box.createRigidArea(new Dimension(0, 5)));
    b2.setAlignmentX(CENTER_ALIGNMENT);
    contentPane.add(b2);

    displayWindow.setContentPane(contentPane);
    displayWindow.pack();
    displayWindow.setVisible(true);
}