Example usage for javax.swing JPanel setAlignmentX

List of usage examples for javax.swing JPanel setAlignmentX

Introduction

In this page you can find the example usage for javax.swing JPanel 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 static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));

    JPanel a = new JPanel();
    a.setAlignmentX(Component.CENTER_ALIGNMENT);
    a.setPreferredSize(new Dimension(100, 100));
    a.setMaximumSize(new Dimension(100, 100)); // set max = pref
    a.setBorder(BorderFactory.createTitledBorder("aa"));
    JPanel b = new JPanel();
    b.setAlignmentX(Component.CENTER_ALIGNMENT);
    b.setPreferredSize(new Dimension(50, 50));
    b.setMaximumSize(new Dimension(50, 50)); // set max = pref
    b.setBorder(BorderFactory.createTitledBorder("bb"));

    frame.getContentPane().add(a);//w ww  .  ja v a  2 s.c o m
    frame.getContentPane().add(b);
    frame.pack();
    frame.setVisible(true);
}

From source file:TwoButtons.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JPanel basic = new JPanel();
    basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS));
    f.add(basic);/*from  www .j  av  a 2 s .c  om*/

    basic.add(Box.createVerticalGlue());

    JPanel bottom = new JPanel();
    bottom.setAlignmentX(1f);
    bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));

    JButton ok = new JButton("OK");
    JButton close = new JButton("Close");

    bottom.add(ok);
    bottom.add(Box.createRigidArea(new Dimension(5, 0)));
    bottom.add(close);
    bottom.add(Box.createRigidArea(new Dimension(15, 0)));

    basic.add(bottom);
    basic.add(Box.createRigidArea(new Dimension(0, 15)));

    f.setSize(300, 250);

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:net.pandoragames.far.ui.swing.component.ButtonPanel.java

/**
 * Initialises the BUTTON panel./*  w  w  w.  j a  va 2 s . c o  m*/
 * @param config configuration properties
 * @param componentRepository repository for shared components
 */
private JPanel initButtonPannel(SwingConfig config, ComponentRepository componentRepository) {

    JPanel buttonPannel = new JPanel();
    buttonPannel.setAlignmentX(Component.LEFT_ALIGNMENT);
    buttonPannel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    // FIND
    if (operationType == OperationType.FIND) {
        JButton findButton = new JButton(localizer.localize("button.find"));
        componentRepository.getOperationCallBackListener().addComponentStartDisabled(findButton,
                OperationType.FIND);
        componentRepository.getOperationCallBackListener().addComponentTerminationEnabled(findButton,
                OperationType.FIND);
        findButton.addActionListener(componentRepository.getFindCommand());
        findButton.addActionListener(new ReorderFilePatternListListener(componentRepository.getFindForm(),
                config.getFileNamePatternListModel()));
        buttonPannel.add(findButton);
    }
    // REPLACE
    if (operationType == OperationType.REPLACE) {
        JButton replaceButton = new JButton(localizer.localize("button.replace"));
        replaceButton.setEnabled(false);
        componentRepository.getOperationCallBackListener().addComponentTerminationEnabled(replaceButton,
                OperationType.FIND);
        componentRepository.getResetDispatcher().addToBeDisabled(replaceButton);
        componentRepository.getSearchBaseListener().addToBeDisabled(replaceButton);
        ConfirmReplaceListener replaceListener = new ConfirmReplaceListener(componentRepository.getRootWindow(),
                config, componentRepository.getReplaceForm());
        replaceListener.addActionListener(componentRepository.getReplaceCommand());
        replaceButton.addActionListener(replaceListener);
        buttonPannel.add(replaceButton);
    }
    // RENAME
    if (operationType == OperationType.RENAME) {
        JButton renameButton = new JButton(componentRepository.getRenameCommand());
        renameButton.setEnabled(false);
        componentRepository.getResetDispatcher().addToBeDisabled(renameButton);
        buttonPannel.add(renameButton);
    }
    // CANCEL
    JButton cancelButton = new JButton(localizer.localize("button.cancel"));
    cancelButton.setEnabled(false);
    componentRepository.getOperationCallBackListener().addComponentStartEnabled(cancelButton,
            OperationType.ANY);
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            backend.abort();
        }
    });
    buttonPannel.add(cancelButton);
    componentRepository.getResetDispatcher().addToBeDisabled(cancelButton);
    // UNDO
    if (operationType == OperationType.REPLACE) {
        JButton undoButton = new JButton(localizer.localize("button.undo"));
        undoButton.setEnabled(false);
        componentRepository.getOperationCallBackListener().addComponentTerminationEnabled(undoButton,
                OperationType.REPLACE);
        componentRepository.getOperationCallBackListener().addComponentStartDisabled(undoButton,
                OperationType.FIND);
        undoButton.addActionListener(componentRepository.getUndoListener());
        undoButton.addActionListener(new OnClickDisable(undoButton));
        buttonPannel.add(undoButton);
    }
    // RESET
    JButton clearButton = new JButton(localizer.localize("button.reset"));
    clearButton.addActionListener(componentRepository.getResetDispatcher());
    buttonPannel.add(clearButton);
    // this.add( buttonPannel );
    return buttonPannel;
}

From source file:gda.util.userOptions.UserOptionsDialog.java

/**
 * @param frame/* w  ww  . j a  v a  2  s  .  com*/
 * @param parent
 * @param options
 */
public UserOptionsDialog(JFrame frame, Component parent, UserOptions options) {
    super(frame, options.title, true);
    this.frame = frame;
    this.options = options;
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    label = new JLabel(options.title != null ? options.title : "");
    label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    label.setAlignmentX(Component.CENTER_ALIGNMENT);
    JPanel pane = makePane();
    // pane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    pane.setAlignmentX(Component.CENTER_ALIGNMENT);
    // pane.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    panel.add(label);
    panel.add(pane);

    JPanel btnPanel = new JPanel();
    btnPanel.setLayout(new BoxLayout(btnPanel, BoxLayout.X_AXIS));

    JButton okButton = new JButton("OK");
    okButton.addActionListener(this);

    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(this);

    JButton defButton = new JButton("Default");
    defButton.addActionListener(this);

    JButton resetButton = new JButton("Reset");
    resetButton.addActionListener(this);

    btnPanel.add(Box.createHorizontalGlue());
    btnPanel.add(okButton);
    btnPanel.add(Box.createHorizontalGlue());
    btnPanel.add(cancelButton);
    btnPanel.add(Box.createHorizontalGlue());
    btnPanel.add(defButton);
    btnPanel.add(Box.createHorizontalGlue());
    btnPanel.add(resetButton);
    btnPanel.add(Box.createHorizontalGlue());

    btnPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    panel.add(btnPanel);

    getContentPane().add(panel);
    getRootPane().setDefaultButton(cancelButton);
    pack();
    setLocationRelativeTo(parent);
    setVisible(true);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}

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

public void doGui() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel noteLbl = new JLabel(
            "<html><div style='width : 500px;'>Pls select a value to choose an Weapon or you can create a new "
                    + "Weapon entity below. Once selected a weapon, its' details will be available below</div></html>");
    noteLbl.setAlignmentX(0);/* w ww . j av a 2  s  .  c  om*/
    add(noteLbl);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (Item item : GameBean.weaponDetails) {
        if (item instanceof Weapon) {
            model.addElement(((Weapon) item).getName());
        }
    }
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setAlignmentX(0);
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(Box.createVerticalStrut(10));
    add(comboBox);
    add(Box.createVerticalStrut(10));
    JPanel panel1 = new JPanel();
    panel1.setAlignmentX(0);
    panel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel1.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    JLabel weaponDtsLbl = new JLabel("Weapon Details : ");
    weaponDtsLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    panel1.add(weaponDtsLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    panel1.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    panel1.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel weaponTypeLbl = new JLabel("Weapon Type : ");
    panel1.add(weaponTypeLbl, c);
    c.gridx = 1;
    JComboBox weaponType = new JComboBox(Configuration.weaponTypes);
    weaponType.setSelectedIndex(0);
    weaponType.setPreferredSize(name.getPreferredSize());
    System.out.println(name.getPreferredSize());
    panel1.add(weaponType, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel attackRangeLbl = new JLabel("Attack Range : ");
    panel1.add(attackRangeLbl, c);
    c.gridx = 1;
    JTextField attackRange = new JTextField("");
    attackRange.setColumns(20);
    panel1.add(attackRange, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    panel1.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    panel1.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    panel1.add(submit, c);
    c.gridx = 0;
    c.gridy = 6;
    c.gridwidth = 2;
    c.weighty = 0;
    c.weightx = 1;
    validationMess = new JLabel("Pls enter all the fields or pls choose a weapon from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    panel1.add(validationMess, c);
    //        c.fill = GridBagConstraints.BOTH;
    //        c.gridy = 7;
    //        c.weightx = 1;
    //        c.weighty = 1;
    //        panel1.add(new JLabel(""), c);
    panel1.setBorder(LineBorder.createGrayLineBorder());
    add(panel1);
    add(Box.createVerticalGlue());
}

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

public void doGui() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel noteLbl = new JLabel("Pls select a value to choose an enemy or you can create a new "
            + "Enemy entity below. Once selected an Enemy character, its' details will be available below");
    noteLbl.setAlignmentX(0);//from   w  ww .  j a  va  2  s.c  o m
    //        noteLbl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(noteLbl);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (GameCharacter character : GameBean.enemyDetails) {
        System.out.println(character.getName());
        model.addElement(character.getName());
    }
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setAlignmentX(0);
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(Box.createVerticalStrut(10));
    add(comboBox);
    add(Box.createVerticalStrut(10));
    JPanel panel1 = new JPanel();
    panel1.setAlignmentX(0);
    panel1.setBorder(LineBorder.createGrayLineBorder());
    panel1.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    JLabel enemyDtlLbl = new JLabel("Enemy Character Details : ");
    enemyDtlLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    panel1.add(enemyDtlLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    panel1.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    panel1.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel imageLbl = new JLabel("Image Path : ");
    panel1.add(imageLbl, c);
    c.gridx = 1;
    JTextField image = new JTextField("");
    image.setColumns(20);
    panel1.add(image, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel healthLbl = new JLabel("Health Pts : ");
    panel1.add(healthLbl, c);
    c.gridx = 1;
    JTextField health = new JTextField("");
    health.setColumns(20);
    panel1.add(health, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    panel1.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    panel1.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    JLabel armoursPtsLbl = new JLabel("Armour Points : ");
    panel1.add(armoursPtsLbl, c);
    c.gridx = 1;
    JTextField armourPts = new JTextField("");
    armourPts.setColumns(20);
    panel1.add(armourPts, c);
    c.gridx = 0;
    c.gridy = 6;
    JLabel attackRngeLbl = new JLabel("Attack Range : ");
    panel1.add(attackRngeLbl, c);
    c.gridx = 1;
    JTextField attackRnge = new JTextField("");
    attackRnge.setColumns(20);
    panel1.add(attackRnge, c);
    c.gridx = 0;
    c.gridy = 7;
    JLabel movementLbl = new JLabel("Movement : ");
    panel1.add(movementLbl, c);
    c.gridx = 1;
    JTextField movement = new JTextField("");
    movement.setColumns(20);
    panel1.add(movement, c);
    c.gridx = 0;
    c.gridy = 8;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    panel1.add(submit, c);
    add(panel1);
    c.gridx = 0;
    c.gridy = 9;
    JLabel validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    add(validationMess, c);
    add(Box.createVerticalGlue());
}

From source file:com.devoteam.srit.xmlloader.core.report.derived.DerivedCounter.java

public void addMouseListenerForGraph(JPanel panel) {
    if (/*this instanceof StatAverage || this instanceof StatFlow*/ true) {
        panel.addMouseListener(new MouseListener() {

            java.awt.Color lastColor;

            public void mouseClicked(MouseEvent e) {
            }// w  w  w .  ja va2 s . co m

            public void mousePressed(MouseEvent e) {
                JFrameRTStats.instance().getJPanelBottom().removeAll();

                JPanel longpanel = generateLongRTStats();
                longpanel.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT);
                longpanel.setAlignmentY(java.awt.Component.TOP_ALIGNMENT);
                JFrameRTStats.instance().getJPanelBottom().add(longpanel);

                // We add graphics to jPanelBottom
                JFrameRTStats.instance().getJPanelBottom().add(getChartPanel());
                // We save the StatKey selected
                ModelTreeRTStats.instance().setStatSelected(id);
                // We update the panel for display the graph
                JFrameRTStats.instance().updatePanel();
            }

            public void mouseReleased(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet.");
            }

            public void mouseEntered(MouseEvent e) {
                lastColor = e.getComponent().getBackground();
                e.getComponent().setBackground(ModelTreeRTStats.instance().getColorByString("selectForGraph"));
            }

            public void mouseExited(MouseEvent e) {
                e.getComponent().setBackground(lastColor);
            }
        });
    }
}

From source file:org.obiba.onyx.jade.instrument.gehealthcare.CardiosoftInstrumentRunner.java

/**
 * Create an information dialog that tells the user to wait while the data is being processed.
 *//* w  ww . j av  a  2s  .  co  m*/
private void showProcessingDialog() {

    JPanel messagePanel = new JPanel();
    messagePanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    messagePanel.setLayout(new BoxLayout(messagePanel, BoxLayout.Y_AXIS));

    JLabel message = new JLabel(ecgResourceBundle.getString("Message.ProcessingEcgMeasurement"));
    message.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
    messagePanel.add(message);

    JLabel subMessage = new JLabel(ecgResourceBundle.getString("Message.ProcessingEcgMeasurementInstructions"));
    subMessage.setFont(new Font(Font.DIALOG, Font.PLAIN, 14));
    subMessage.setForeground(Color.RED);
    messagePanel.add(subMessage);

    JFrame window = new JFrame();
    window.add(messagePanel);
    window.pack();

    // Make sure dialog stays on top of all other application windows.
    window.setAlwaysOnTop(true);
    window.setLocationByPlatform(true);

    // Center dialog horizontally at the bottom of the screen.
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    window.setLocation((screenSize.width - window.getWidth()) / 2, screenSize.height - window.getHeight() - 70);

    window.setEnabled(false);
    window.setVisible(true);

}

From source file:components.ComboBoxDemo2.java

public ComboBoxDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z",
            "EEE, MMM d, ''yy", "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" };

    currentPattern = patternExamples[0];

    //Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Enter the pattern string or");
    JLabel patternLabel2 = new JLabel("select one from the list:");

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setEditable(true);//from  w  ww  . jav a2 s.  co  m
    patternList.addActionListener(this);

    //Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); //== LEFT
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Lay out everything.
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternPanel.add(patternList);

    JPanel resultPanel = new JPanel(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

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

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    reformat();
}

From source file:ComboBoxDemo2.java

public ComboBoxDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z",
            "EEE, MMM d, ''yy", "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" };

    currentPattern = patternExamples[0];

    // Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Enter the pattern string or");
    JLabel patternLabel2 = new JLabel("select one from the list:");

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setEditable(true);//from w w  w.j ava2 s . c  om
    patternList.addActionListener(this);

    // Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); // ==
                                                                          // LEFT
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Lay out everything.
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternPanel.add(patternList);

    JPanel resultPanel = new JPanel(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

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

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    reformat();
}