Example usage for javax.swing BoxLayout X_AXIS

List of usage examples for javax.swing BoxLayout X_AXIS

Introduction

In this page you can find the example usage for javax.swing BoxLayout X_AXIS.

Prototype

int X_AXIS

To view the source code for javax.swing BoxLayout X_AXIS.

Click Source Link

Document

Specifies that components should be laid out left to right.

Usage

From source file:BRHInit.java

public void showLoginPrompt() {
    if (login_window == null) {
        login_window = new JFrame("BRH Console");
        login_window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel top_panel = new JPanel();
        login_window.getContentPane().add(top_panel);

        top_panel.setLayout(new BoxLayout(top_panel, BoxLayout.Y_AXIS));
        top_panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        JPanel p = new JPanel();
        top_panel.add(p);/*from w  w w .ja va 2s  .c  o m*/
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

        JPanel col_panel = new JPanel();
        p.add(col_panel);
        col_panel.setLayout(new BoxLayout(col_panel, BoxLayout.Y_AXIS));

        col_panel.add(new JLabel("email"));
        col_panel.add(Box.createRigidArea(new Dimension(0, 5)));
        col_panel.add(new JLabel("password"));

        p.add(Box.createRigidArea(new Dimension(5, 0)));

        col_panel = new JPanel();
        p.add(col_panel);
        col_panel.setLayout(new BoxLayout(col_panel, BoxLayout.Y_AXIS));

        col_panel.add(email = new JTextField(20));
        col_panel.add(Box.createRigidArea(new Dimension(0, 5)));
        col_panel.add(password = new JPasswordField());

        if (email_arg != null)
            email.setText(email_arg);
        if (password_arg != null)
            password.setText(password_arg);

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

        p = new JPanel();
        top_panel.add(p);
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

        p.add(Box.createHorizontalGlue());
        p.add(login_ok = new JButton("OK"));
        p.add(Box.createRigidArea(new Dimension(5, 0)));
        p.add(login_cancel = new JButton("Cancel"));
        p.add(Box.createHorizontalGlue());

        login_ok.addActionListener(this);
        login_cancel.addActionListener(this);

        login_window.pack();
    }

    cookie = null;
    login_window.setVisible(true);
}

From source file:fll.scheduler.ChooseChallengeDescriptor.java

private void initComponents() {
    getContentPane().setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.weightx = 1;//from w w w  .  j  av a  2 s.  c  o m
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.BOTH;
    final JTextArea instructions = new JTextArea(
            "Choose a challenge description from the drop down list OR choose a file containing your custom challenge description.",
            3, 40);
    instructions.setEditable(false);
    instructions.setWrapStyleWord(true);
    instructions.setLineWrap(true);
    getContentPane().add(instructions, gbc);

    gbc = new GridBagConstraints();
    mCombo = new JComboBox<DescriptionInfo>();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    getContentPane().add(mCombo, gbc);
    mCombo.setRenderer(new DescriptionInfoRenderer());
    mCombo.setEditable(false);
    final List<DescriptionInfo> descriptions = DescriptionInfo.getAllKnownChallengeDescriptionInfo();
    for (final DescriptionInfo info : descriptions) {
        mCombo.addItem(info);
    }

    mFileField = new JLabel();
    gbc = new GridBagConstraints();
    gbc.weightx = 1;
    getContentPane().add(mFileField, gbc);

    final JButton chooseButton = new JButton("Choose File");
    gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    getContentPane().add(chooseButton, gbc);
    chooseButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent ae) {
            mFileField.setText(null);

            final JFileChooser fileChooser = new JFileChooser();
            final FileFilter filter = new BasicFileFilter("FLL Description (xml)", new String[] { "xml" });
            fileChooser.setFileFilter(filter);

            final int returnVal = fileChooser.showOpenDialog(ChooseChallengeDescriptor.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final File selectedFile = fileChooser.getSelectedFile();
                mFileField.setText(selectedFile.getAbsolutePath());
            }
        }
    });

    final Box buttonPanel = new Box(BoxLayout.X_AXIS);
    gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    getContentPane().add(buttonPanel, gbc);

    buttonPanel.add(Box.createHorizontalGlue());
    final JButton ok = new JButton("Ok");
    buttonPanel.add(ok);
    ok.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent ae) {

            // use the selected description if nothing is entered in the file box
            final DescriptionInfo descriptionInfo = mCombo.getItemAt(mCombo.getSelectedIndex());
            if (null != descriptionInfo) {
                mSelected = descriptionInfo.getURL();
            }

            final String text = mFileField.getText();
            if (!StringUtils.isEmpty(text)) {
                final File file = new File(text);
                if (file.exists()) {
                    try {
                        mSelected = file.toURI().toURL();
                    } catch (final MalformedURLException e) {
                        throw new FLLInternalException("Can't turn file into URL?", e);
                    }
                }
            }

            setVisible(false);
        }
    });

    final JButton cancel = new JButton("Cancel");
    buttonPanel.add(cancel);
    cancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent ae) {
            mSelected = null;
            setVisible(false);
        }
    });

    pack();
}

From source file:CubaHSQLDBServer.java

private CubaHSQLDBServer() {
    Font monospaced = Font.decode("monospaced");

    statusArea = new JTextArea(2, 80);
    statusArea.setFont(monospaced);//from ww  w . j  a  v a 2 s .  co m
    statusArea.setMargin(new Insets(5, 5, 5, 5));
    exceptionArea = new JTextArea(26, 80);
    exceptionArea.setFont(monospaced);
    exceptionArea.setMargin(new Insets(5, 5, 5, 5));
    JPanel exceptionWrapperContainer = new JPanel();
    exceptionWrapperContainer.setLayout(new BorderLayout(0, 0));
    exceptionWrapperContainer.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
    exceptionWrapperContainer.add(exceptionArea);
    JPanel statusWrapperContainer = new JPanel();
    statusWrapperContainer.setLayout(new BorderLayout(0, 0));
    statusWrapperContainer.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
    statusWrapperContainer.add(statusArea);
    addCopyPopup(statusArea);
    addCopyPopup(exceptionArea);

    exceptionBox = new JPanel();
    LayoutBuilder.create(exceptionBox, BoxLayout.Y_AXIS).addSpace(5).addComponent(exceptionWrapperContainer);

    LayoutBuilder.create(this.getContentPane(), BoxLayout.X_AXIS).addSpace(5).addContainer(BoxLayout.Y_AXIS)
            .addSpace(5).addComponent(statusWrapperContainer).addComponent(exceptionBox).addSpace(5)
            .returnToParent().addSpace(5);

    statusArea.setEditable(false);
    exceptionArea.setEditable(false);
    exceptionBox.setVisible(false);
    exceptionArea.setBackground(new Color(255, 255, 212));
    this.pack();
    this.setResizable(true);
    this.setTitle("HSQLDB Server");

    try {
        this.setIconImage(ImageIO.read(getClass().getResourceAsStream("/icons/database.png")));
    } catch (IOException e) {
        throw new IllegalStateException("Unable to find icon for HSQLDB window");
    }
}

From source file:com.intel.stl.ui.common.view.DistributionPiePanel.java

public void setLabels(String[] itemNames, ImageIcon[] icons, int labelColumns) {
    if (icons.length != itemNames.length) {
        throw new IllegalArgumentException(
                "Inconsistent number of items. " + " itemNames=" + itemNames.length + " icons=" + icons.length);
    }//w  w w .j a  va2  s  .  c om

    labels = new JLabel[icons.length];
    for (int i = 0; i < icons.length; i++) {
        labels[i] = new JLabel(itemNames[i], icons[i], JLabel.LEFT);
    }

    int rows = 1;
    if (labelColumns <= 0) {
        labelPanel.setLayout(new FlowLayout());
        for (JLabel label : labels) {
            labelPanel.add(label);
        }
    } else {
        BoxLayout layout = new BoxLayout(labelPanel, BoxLayout.X_AXIS);
        labelPanel.setLayout(layout);
        JPanel[] columns = new JPanel[labelColumns];
        for (int i = 0; i < columns.length; i++) {
            labelPanel.add(Box.createHorizontalGlue());
            columns[i] = new JPanel();
            columns[i].setOpaque(false);
            columns[i].setBorder(BorderFactory.createEmptyBorder(2, 3, 2, 3));
            BoxLayout cLayout = new BoxLayout(columns[i], BoxLayout.Y_AXIS);
            columns[i].setLayout(cLayout);
            labelPanel.add(columns[i]);
        }
        labelPanel.add(Box.createHorizontalGlue());
        rows = (int) Math.ceil((double) labels.length / labelColumns);
        int index = 0;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < labelColumns; j++) {
                columns[i].add(index < labels.length ? labels[index] : Box.createGlue());
                index += 1;
            }
        }
    }
}

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

/**
 * The default constructor./*from  ww  w. jav  a 2s  .c om*/
 */
public JFieldsEditor() {
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    scrollPane = new JScrollPane();
    add(scrollPane);
}

From source file:gdt.jgui.console.JItemPanel.java

/**
 * The default constructor./*from  ww  w .  jav  a2s .  c o m*/
 */
public JItemPanel() {
    super();
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    setAlignmentX(Component.LEFT_ALIGNMENT);
}

From source file:net.sf.maltcms.chromaui.foldChangeViewer.ui.FoldChangeViewTopComponent.java

public void initialize(final IChromAUIProject project,
        final ADataset1D<StatisticsContainer, FoldChangeElement> ds) {
    if (initialized.compareAndSet(false, true)) {
        final ProgressHandle handle = ProgressHandleFactory.createHandle("Loading chart");
        final JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
        final JPanel box = new JPanel();
        box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
        box.add(Box.createHorizontalGlue());
        box.add(progressComponent);/*from www . ja  va2  s .  c om*/
        box.add(Box.createHorizontalGlue());
        add(box, BorderLayout.CENTER);
        AProgressAwareRunnable runnable = new AProgressAwareRunnable() {
            @Override
            public void run() {
                try {
                    handle.start();
                    handle.progress("Initializing Overlays...");
                    if (project != null) {
                        ic.add(project);
                    }
                    dataset = ds;
                    annotations = new ArrayList<XYAnnotation>(0);
                    final DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
                    ic.add(ds);
                    for (int i = 0; i < ds.getSeriesCount(); i++) {
                        ic.add(ds.getSource(i));
                    }
                    handle.progress("Initializing Settings and Properties...");
                    ic.add(new Properties());
                    sp = new SettingsPanel();
                    ic.add(sp);
                    handle.progress("Creating panel...");
                    jp = new FoldChangeViewPanel(ic, getLookup(), ds);
                    ic.add(jp);
                    ic.add(this);
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            //EDT stuff
                            setDisplayName("Fold change view of " + ds.getDisplayName());
                            setToolTipText(ds.getDescription());
                            remove(box);
                            add(jp, BorderLayout.CENTER);
                            load();
                        }
                    });
                } finally {
                    handle.finish();
                }
            }
        };
        runnable.setProgressHandle(handle);
        AProgressAwareRunnable.createAndRun("Creating chart", runnable);
    }
}

From source file:com.eviware.soapui.impl.rest.panels.mock.RestMockResponseDesktopPanel.java

private JComponent createMediaTypeCombo() {
    MediaTypeComboBox mediaTypeComboBox = new MediaTypeComboBox(this.getModelItem());
    mediaTypeComboBox.addItemListener(new ItemListener() {
        @Override//  w w w  . j  av  a  2s .  c  o m
        public void itemStateChanged(ItemEvent e) {
            setMediaType(getResponseEditor().getInputArea(), e.getItem().toString());
        }
    });
    JComponent innerPanel = createPanelWithLabel("Content | Media type: ", mediaTypeComboBox);

    JPanel outerPanel = new JPanel();
    outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.X_AXIS));
    outerPanel.add(innerPanel);
    outerPanel.add(Box.createHorizontalGlue());
    outerPanel
            .add(UISupport.createFormButton(new ShowOnlineHelpAction(HelpUrls.REST_MOCK_RESPONSE_EDITOR_BODY)));

    return outerPanel;
}

From source file:gdt.jgui.entity.JEntityDigestDisplay.java

/**
 * The default constructor.//from  ww  w .java  2  s.c om
 */
public JEntityDigestDisplay() {
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    scrollPane = new JScrollPane();
    add(scrollPane);
}

From source file:UndoableToggleApp4.java

public UndoableToggleApp4() {

    // Create some toggle buttons (and subclasses).
    tog = new JToggleButton("ToggleButton");
    cb = new JCheckBox("CheckBox");
    radio = new JRadioButton("RadioButton");

    // Add our listener to the buttons.
    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);//from www. ja  v a2 s .  com
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    // Lay out the buttons.
    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    // Create undo, redo, start, and end buttons.
    startButton = new JButton("Start");
    endButton = new JButton("End");
    undoButton = new JButton("Undo");
    redoButton = new JButton("Redo");
    startButton.setEnabled(true);
    endButton.setEnabled(false);
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);

    // Add a listener to the start button. It creates a new StateEdit,
    // passing in this frame as the StateEditable.
    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit = new StateEdit(UndoableToggleApp4.this);
            startButton.setEnabled(false);
            endButton.setEnabled(true);
            //undoButton.setEnabled(edit.canUndo());
            //
            // NOTE: We really don't want to be able to undo until end() is
            // pressed,
            // but StateEdit does not enforce this for us!
            undoButton.setEnabled(false);
            redoButton.setEnabled(edit.canRedo());
        }
    });

    // Add a listener to the end button. It will call end() on the
    // StateEdit.
    endButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit.end();
            startButton.setEnabled(true);
            endButton.setEnabled(false);
            undoButton.setEnabled(edit.canUndo());
            redoButton.setEnabled(edit.canRedo());
        }
    });

    // Add a listener to the undo button. It attempts to call undo() on the
    // current edit, then enables/disables the undo/redo buttons as
    // appropriate.
    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.undo();
            } catch (CannotUndoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    // Add a redo listener: just like the undo listener.
    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.redo();
            } catch (CannotRedoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    // Lay out the state/end and undo/redo buttons.
    Box undoRedoBox = new Box(BoxLayout.X_AXIS);
    undoRedoBox.add(Box.createGlue());
    undoRedoBox.add(startButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(endButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(undoButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(redoButton);
    undoRedoBox.add(Box.createGlue());

    // Lay out the main frame.
    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(buttonBox, BorderLayout.CENTER);
    content.add(undoRedoBox, BorderLayout.SOUTH);
    setSize(400, 150);
}