Example usage for javax.swing BoxLayout LINE_AXIS

List of usage examples for javax.swing BoxLayout LINE_AXIS

Introduction

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

Prototype

int LINE_AXIS

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

Click Source Link

Document

Specifies that components should be laid out in the direction of a line of text as determined by the target container's ComponentOrientation property.

Usage

From source file:org.isatools.isacreator.optionselector.OptionGroup.java

public OptionGroup(int alignment, boolean singleSelection, int leftPadding) {
    this.singleSelection = singleSelection;
    this.alignment = alignment;

    availableOptions = new ListOrderedMap<T, OptionItem>();

    setLayout(/*  w w w.  j  ava  2s  . c  om*/
            new BoxLayout(this, alignment == HORIZONTAL_ALIGNMENT ? BoxLayout.LINE_AXIS : BoxLayout.PAGE_AXIS));
    add(Box.createHorizontalStrut(leftPadding));
    setOpaque(false);
}

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

/**
 * Create the FlatButton panel - a panel which contains graphical representations of the options available
 * to the user when interacting with the software.
 *///from   ww  w .j a v a2 s  .  co  m
private void createButtonPanel() {

    spreadsheetFunctionPanel = new JPanel();
    spreadsheetFunctionPanel.setLayout(new BoxLayout(spreadsheetFunctionPanel, BoxLayout.LINE_AXIS));
    spreadsheetFunctionPanel.setBackground(UIHelper.BG_COLOR);

    addRow = new JLabel(addRowButton);
    addRow.setToolTipText("<html><b>add row</b>" + "<p>add a new row to the table</p></html>");
    addRow.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            addRow.setIcon(addRowButton);
            showMultipleRowsGUI();
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            addRow.setIcon(addRowButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            addRow.setIcon(addRowButton);
        }
    });

    deleteRow = new JLabel(deleteRowButton);
    deleteRow.setToolTipText("<html><b>remove row</b>" + "<p>remove selected row from table</p></html>");
    deleteRow.setEnabled(false);
    deleteRow.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            deleteRow.setIcon(deleteRowButton);
            if (table.getSelectedRow() != -1) {
                if (!(table.getSelectedRowCount() > 1)) {
                    spreadsheetFunctions.deleteRow(table.getSelectedRow());
                } else {
                    spreadsheetFunctions.deleteRow(table.getSelectedRows());
                }

            }
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            deleteRow.setIcon(deleteRowButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            deleteRow.setIcon(deleteRowButton);
        }
    });

    deleteColumn = new JLabel(deleteColumnButton);
    deleteColumn
            .setToolTipText("<html><b>remove column</b>" + "<p>remove selected column from table</p></html>");
    deleteColumn.setEnabled(false);
    deleteColumn.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            deleteColumn.setIcon(deleteColumnButton);
            if (!(table.getSelectedColumns().length > 1)) {
                spreadsheetFunctions.deleteColumn(table.getSelectedColumn());
            } else {
                showColumnErrorMessage();
            }
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            deleteColumn.setIcon(deleteColumnButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            deleteColumn.setIcon(deleteColumnButton);
        }
    });

    multipleSort = new JLabel(multipleSortButton);
    multipleSort.setToolTipText(
            "<html><b>multiple sort</b>" + "<p>perform a multiple sort on the table</p></html>");
    multipleSort.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            multipleSort.setIcon(multipleSortButton);
            showMultipleColumnSortGUI();
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            multipleSort.setIcon(multipleSortButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            multipleSort.setIcon(multipleSortButton);
        }
    });

    copyColDown = new JLabel(copyColDownButton);
    copyColDown.setToolTipText("<html><b>copy column downwards</b>"
            + "<p>duplicate selected column and copy it from the current</p>"
            + "<p>position down to the final row in the table</p></html>");
    copyColDown.setEnabled(false);
    copyColDown.addMouseListener(new MouseAdapter() {

        public void mouseExited(MouseEvent mouseEvent) {
            copyColDown.setIcon(copyColDownButton);
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            copyColDown.setIcon(copyColDownButtonOver);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            copyColDown.setIcon(copyColDownButton);

            final int row = table.getSelectedRow();
            final int col = table.getSelectedColumn();

            if (row != -1 && col != -1) {
                JOptionPane copyColDownConfirmationPane = new JOptionPane(
                        "<html><b>Confirm Copy of Column...</b><p>Are you sure you wish to copy "
                                + "this column downwards?</p><p>This Action can not be undone!</p></html>",
                        JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);

                copyColDownConfirmationPane.setIcon(copyColumnDownWarningIcon);
                UIHelper.applyOptionPaneBackground(copyColDownConfirmationPane, UIHelper.BG_COLOR);

                copyColDownConfirmationPane.addPropertyChangeListener(new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent event) {
                        if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
                            int lastOptionAnswer = Integer.valueOf(event.getNewValue().toString());
                            parentFrame.hideSheet();
                            if (lastOptionAnswer == JOptionPane.YES_OPTION) {
                                spreadsheetFunctions.copyColumnDownwards(row, col);
                            }
                        }
                    }
                });
                parentFrame.showJDialogAsSheet(
                        copyColDownConfirmationPane.createDialog(Spreadsheet.this, "Copy Column?"));
            }
        }
    });

    copyRowDown = new JLabel(copyRowDownButton);
    copyRowDown.setToolTipText(
            "<html><b>copy row downwards</b>" + "<p>duplicate selected row and copy it from the current</p>"
                    + "<p>position down to the final row</p></html>");
    copyRowDown.setEnabled(false);
    copyRowDown.addMouseListener(new MouseAdapter() {

        public void mouseExited(MouseEvent mouseEvent) {
            copyRowDown.setIcon(copyRowDownButton);
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            copyRowDown.setIcon(copyRowDownButtonOver);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            copyRowDown.setIcon(copyRowDownButton);

            final int row = table.getSelectedRow();

            JOptionPane copyRowDownConfirmationPane = new JOptionPane(
                    "<html><b>Confirm Copy of Row...</b><p>Are you sure you wish to copy "
                            + "this row downwards?</p><p>This Action can not be undone!</p>",
                    JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);

            copyRowDownConfirmationPane.setIcon(copyRowDownWarningIcon);

            UIHelper.applyOptionPaneBackground(copyRowDownConfirmationPane, UIHelper.BG_COLOR);

            copyRowDownConfirmationPane.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent event) {
                    if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
                        int lastOptionAnswer = Integer.valueOf(event.getNewValue().toString());
                        parentFrame.hideSheet();
                        if (lastOptionAnswer == JOptionPane.YES_OPTION) {
                            spreadsheetFunctions.copyRowDownwards(row);
                        }
                    }
                }
            });
            parentFrame.showJDialogAsSheet(
                    copyRowDownConfirmationPane.createDialog(Spreadsheet.this, "Copy Row Down?"));
        }
    });

    addProtocol = new JLabel(addProtocolButton);
    addProtocol.setToolTipText(
            "<html><b>add a protocol column</b>" + "<p>Add a protocol column to the table</p></html>");
    addProtocol.addMouseListener(new MouseAdapter() {

        public void mouseEntered(MouseEvent mouseEvent) {
            addProtocol.setIcon(addProtocolButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            addProtocol.setIcon(addProtocolButton);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            addProtocol.setIcon(addProtocolButton);
            if (addProtocol.isEnabled()) {
                FieldObject fo = new FieldObject(table.getColumnCount(), "Protocol REF",
                        "Protocol used for experiment", DataTypes.LIST, "", false, false, false);

                fo.setFieldList(studyDataEntryEnvironment.getProtocolNames());

                spreadsheetFunctions.addFieldToReferenceObject(fo);

                spreadsheetFunctions.addColumnAfterPosition("Protocol REF", null, fo.isRequired(), -1);
            }
        }
    });

    addFactor = new JLabel(addFactorButton);
    addFactor.setToolTipText(
            "<html><b>add a factor column</b>" + "<p>Add a factor column to the table</p></html>");
    addFactor.addMouseListener(new MouseAdapter() {
        public void mouseEntered(MouseEvent mouseEvent) {
            addFactor.setIcon(addFactorButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            addFactor.setIcon(addFactorButton);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            addFactor.setIcon(addFactorButton);
            if (addFactor.isEnabled()) {
                showAddColumnsGUI(AddColumnGUI.ADD_FACTOR_COLUMN);
            }
        }
    });

    addCharacteristic = new JLabel(addCharacteristicButton);
    addCharacteristic.setToolTipText("<html><b>add a characteristic column</b>"
            + "<p>Add a characteristic column to the table</p></html>");
    addCharacteristic.addMouseListener(new MouseAdapter() {
        public void mouseEntered(MouseEvent mouseEvent) {
            addCharacteristic.setIcon(addCharacteristicButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            addCharacteristic.setIcon(addCharacteristicButton);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            addCharacteristic.setIcon(addCharacteristicButton);
            if (addCharacteristic.isEnabled()) {
                showAddColumnsGUI(AddColumnGUI.ADD_CHARACTERISTIC_COLUMN);
            }
        }
    });

    addParameter = new JLabel(addParameterButton);
    addParameter.setToolTipText(
            "<html><b>add a parameter column</b>" + "<p>Add a parameter column to the table</p></html>");
    addParameter.addMouseListener(new MouseAdapter() {
        public void mouseEntered(MouseEvent mouseEvent) {
            addParameter.setIcon(addParameterButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            addParameter.setIcon(addParameterButton);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            addParameter.setIcon(addParameterButton);
            if (addParameter.isEnabled()) {
                showAddColumnsGUI(AddColumnGUI.ADD_PARAMETER_COLUMN);
            }
        }
    });

    undo = new JLabel(undoButton);
    undo.setToolTipText("<html><b>undo previous action<b></html>");
    undo.setEnabled(undoManager.canUndo());
    undo.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            undo.setIcon(undoButton);
            undoManager.undo();

            if (highlightActive) {
                setRowsToDefaultColor();
            }
            table.addNotify();
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            undo.setIcon(undoButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            undo.setIcon(undoButton);
        }
    });

    redo = new JLabel(redoButton);
    redo.setToolTipText("<html><b>redo action<b></html>");
    redo.setEnabled(undoManager.canRedo());
    redo.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            redo.setIcon(redoButton);
            undoManager.redo();

            if (highlightActive) {
                setRowsToDefaultColor();
            }
            table.addNotify();

        }

        public void mouseEntered(MouseEvent mouseEvent) {
            redo.setIcon(redoButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            redo.setIcon(redoButton);
        }
    });

    transpose = new JLabel(transposeIcon);
    transpose.setToolTipText("<html>View a transposed version of this spreadsheet</html>");
    transpose.addMouseListener(new MouseAdapter() {

        public void mouseExited(MouseEvent mouseEvent) {
            transpose.setIcon(transposeIcon);
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            transpose.setIcon(transposeIconOver);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            showTransposeSpreadsheetGUI();
        }
    });

    addButtons();

    if (studyDataEntryEnvironment != null) {
        JPanel labelContainer = new JPanel(new GridLayout(1, 1));
        labelContainer.setBackground(UIHelper.BG_COLOR);

        JLabel lab = UIHelper.createLabel(spreadsheetTitle, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR,
                JLabel.RIGHT);
        lab.setBackground(UIHelper.BG_COLOR);
        lab.setVerticalAlignment(JLabel.CENTER);
        lab.setPreferredSize(new Dimension(200, 30));

        labelContainer.add(lab);

        spreadsheetFunctionPanel.add(labelContainer);
        spreadsheetFunctionPanel.add(Box.createHorizontalStrut(10));
    }

    add(spreadsheetFunctionPanel, BorderLayout.NORTH);
}

From source file:org.isatools.isacreator.visualization.InvestigationInfoPanel.java

public void createGUI() {
    JPanel headerPanel = new JPanel(new GridLayout(1, 2));
    headerPanel.setBackground(UIHelper.BG_COLOR);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
    buttonPanel.setBackground(UIHelper.BG_COLOR);

    headerPanel.add(new JLabel(
            new ImageIcon(getClass().getResource("/images/visualization/investigationinfo.png")), JLabel.LEFT));

    add(headerPanel, BorderLayout.NORTH);

    add(prepareInvestigationInformation(), BorderLayout.CENTER);
}

From source file:org.isatools.isacreator.visualization.StudyInfoPanel.java

public void createGUI() {
    JPanel headerPanel = new JPanel(new GridLayout(1, 2));
    headerPanel.setBackground(UIHelper.BG_COLOR);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
    buttonPanel.setBackground(UIHelper.BG_COLOR);

    headerPanel.add(new JLabel(new ImageIcon(getClass().getResource("/images/visualization/studyinfo.png")),
            JLabel.LEFT));/* w  ww  .j  av a  2 s .co m*/

    add(headerPanel, BorderLayout.NORTH);

    add(prepareStudyInformation(), BorderLayout.CENTER);
}

From source file:org.isatools.isacreatorconfigurator.configui.DataEntryPanel.java

private JPanel createTableListPanel() {

    JPanel container = new JPanel();
    container.setBackground(UIHelper.BG_COLOR);
    container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));

    JLabel lab = new JLabel(tableListTitle);

    container.add(UIHelper.wrapComponentInPanel(lab));
    container.add(Box.createVerticalStrut(5));

    tableModel = new DefaultListModel();
    tableList = new JList(tableModel);
    tableList.setCellRenderer(new TableListRenderer());
    tableList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    tableList.setBackground(UIHelper.BG_COLOR);
    tableList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            try {
                saveCurrentField(false, false);
            } catch (DataNotCompleteException dce) {
                showMessagePane(dce.getMessage(), JOptionPane.ERROR_MESSAGE);
            }/* w w w .j  ava 2s .  c  o  m*/

            MappingObject currentlyEditedTable = getCurrentlySelectedTable();
            ApplicationManager.setCurrentMappingObject(currentlyEditedTable);

            // update the view error button visibility depending on selected tables error state.
            viewErrorsButton.setVisible(areThereErrorsInThisCurrentObject());

            updateTableInfoDisplay(currentlyEditedTable);
            reformFieldList(currentlyEditedTable);
        }
    });

    JScrollPane listScroller = new JScrollPane(tableList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    listScroller.getViewport().setBackground(UIHelper.BG_COLOR);
    listScroller.setBorder(null);
    listScroller.setPreferredSize(new Dimension(((int) (WIDTH * 0.25)), ((int) (HEIGHT * 0.75))));

    IAppWidgetFactory.makeIAppScrollPane(listScroller);

    container.add(listScroller);
    container.add(Box.createVerticalStrut(5));

    tableCountInfo = UIHelper.createLabel("", UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR);
    container.add(UIHelper.wrapComponentInPanel(tableCountInfo));
    container.add(Box.createVerticalStrut(5));

    // create button panel to add and remove tables
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
    buttonPanel.setBackground(UIHelper.BG_COLOR);

    final JLabel addTableButton = new JLabel(addTable, JLabel.LEFT);
    UIHelper.renderComponent(addTableButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    addTableButton.setOpaque(false);

    addTableButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            addTableButton.setIcon(addTableOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            addTableButton.setIcon(addTable);
        }

        public void mousePressed(MouseEvent event) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    addTableButton.setIcon(addTable);
                    applicationContainer.showJDialogAsSheet(addTableUI);
                }
            });

        }

    });

    addTableButton.setToolTipText("<html><b>Add table</b><p>Add a new table definition.</p></html>");

    final JLabel removeTableButton = new JLabel(removeTable, JLabel.LEFT);
    UIHelper.renderComponent(removeTableButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    removeTableButton.setOpaque(false);

    removeTableButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            removeTableButton.setIcon(removeTableOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            removeTableButton.setIcon(removeTable);
        }

        public void mousePressed(MouseEvent event) {
            removeTableButton.setIcon(removeTable);
            if (tableList.getSelectedValue() != null) {
                String selectedTable = tableList.getSelectedValue().toString();
                MappingObject toRemove = null;
                for (MappingObject mo : tableFields.keySet()) {
                    if (mo.getAssayName().equals(selectedTable)) {
                        toRemove = mo;
                        break;
                    }
                }

                if (toRemove != null) {
                    tableFields.remove(toRemove);
                    reformTableList();
                }
            }
        }

    });

    removeTableButton.setToolTipText("<html><b>Remove table</b><p>Remove table from definitions?</p></html>");

    viewErrorsButton = new JLabel(viewErrorsIcon);
    viewErrorsButton.setVisible(false);
    viewErrorsButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            viewErrorsButton.setIcon(viewErrorsIcon);
            // show error pane for current table only.

            Validator validator = new Validator();
            validateFormOrTable(validator, ApplicationManager.getCurrentMappingObject());

            ValidationReport report = validator.getReport();

            ConfigurationValidationUI validationUI = new ConfigurationValidationUI(tableFields.keySet(),
                    report);
            validationUI.createGUI();
            validationUI.setLocationRelativeTo(getApplicationContainer());
            validationUI.setAlwaysOnTop(true);
            validationUI.setVisible(true);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            viewErrorsButton.setIcon(viewErrorsIconOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            viewErrorsButton.setIcon(viewErrorsIcon);
        }
    });

    buttonPanel.add(addTableButton);
    buttonPanel.add(removeTableButton);
    buttonPanel.add(viewErrorsButton);
    buttonPanel.add(Box.createHorizontalGlue());

    container.add(buttonPanel);

    container.add(Box.createVerticalGlue());

    return container;
}

From source file:org.isatools.isacreatorconfigurator.configui.DataEntryPanel.java

private JPanel createFieldListPanel() {

    JPanel container = new JPanel();
    container.setBackground(UIHelper.BG_COLOR);
    container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));

    JPanel headerLab = new JPanel(new GridLayout(1, 1));
    headerLab.setOpaque(false);/*from  ww  w .  j  a v  a2  s .c o  m*/

    JLabel lab = new JLabel(fieldListTitle);
    headerLab.add(lab);

    container.add(headerLab);
    container.add(Box.createVerticalStrut(5));

    elementModel = new DefaultListModel();
    elementList = new ReOrderableJList(elementModel);
    elementList.setCellRenderer(new CustomReOrderableListCellRenderer(elementList));
    elementList.setDragEnabled(true);
    elementList.setBackground(UIHelper.BG_COLOR);

    elementList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            Display selectedNode = (Display) elementList.getSelectedValue();
            if (selectedNode != null) {
                try {
                    saveCurrentField(false, false);
                } catch (DataNotCompleteException dce) {
                    showMessagePane(dce.getMessage(), JOptionPane.ERROR_MESSAGE);
                }
                if (selectedNode instanceof FieldElement) {
                    fieldInterface.setCurrentField((FieldElement) selectedNode);
                    if (currentPage != fieldInterface) {
                        setCurrentPage(fieldInterface);
                    }
                    removeElementButton.setEnabled(!standardISAFields.isFieldRequired(selectedNode.toString()));
                } else {
                    setCurrentPage(structureElement);
                }
            }
        }
    });

    elementList.addPropertyChangeListener("orderChanged", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            updateFieldOrder();

            if (tableList.getSelectedValue() instanceof MappingObject) {
                validateFormOrTable(ApplicationManager.getCurrentMappingObject());
            }
        }
    });

    JScrollPane listScroller = new JScrollPane(elementList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    listScroller.getViewport().setBackground(UIHelper.BG_COLOR);
    listScroller.setBorder(new EmptyBorder(2, 2, 2, 10));
    listScroller.setPreferredSize(new Dimension(((int) (WIDTH * 0.25)), ((int) (HEIGHT * 0.75))));
    IAppWidgetFactory.makeIAppScrollPane(listScroller);

    container.add(listScroller);
    container.add(Box.createVerticalStrut(5));

    elementCountInfo = UIHelper.createLabel("", UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR);

    container.add(UIHelper.wrapComponentInPanel(elementCountInfo));
    container.add(Box.createVerticalStrut(5));

    // create button panel to add and remove tables
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
    buttonPanel.setBackground(UIHelper.BG_COLOR);

    final JLabel addFieldButton = new JLabel(addElement, JLabel.LEFT);
    addFieldButton.setOpaque(false);

    addFieldButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            addFieldButton.setIcon(addElementOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            addFieldButton.setIcon(addElement);
        }

        public void mousePressed(MouseEvent event) {
            addFieldButton.setIcon(addElement);
            showAddFieldUI();
        }

    });

    addFieldButton.setToolTipText(
            "<html><b>Add Field to table</b><p>Add a new field to currently selected table</b></p></html>");

    removeElementButton = new JLabel(removeElement, JLabel.LEFT);
    removeElementButton.setOpaque(false);

    removeElementButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            removeElementButton.setIcon(removeElementOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            removeElementButton.setIcon(removeElement);
        }

        public void mousePressed(MouseEvent event) {
            removeElementButton.setIcon(removeElement);
            if (removeElementButton.isEnabled()) {
                removeSelectedElement();
            }
        }

    });

    removeElementButton.setToolTipText(
            "<html><b>Remove Field from table</b><p>Remove this field from this list and the currently selected table.</b></p></html>");

    final JLabel moveDownButton = new JLabel(moveDown);
    moveDownButton.setOpaque(false);
    moveDownButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            moveDownButton.setIcon(moveDownOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            moveDownButton.setIcon(moveDown);
        }

        public void mousePressed(MouseEvent event) {
            moveDownButton.setIcon(moveDown);
            if (elementList.getSelectedIndex() != -1) {
                int toMoveDown = elementList.getSelectedIndex();

                if (toMoveDown != (elementModel.getSize() - 1)) {
                    swapElements(elementList, elementModel, toMoveDown, toMoveDown + 1);
                }

                updateFieldOrder();
                validateFormOrTable(ApplicationManager.getCurrentMappingObject());
            }
        }
    });

    moveDownButton.setToolTipText(
            "<html><b>Move Field Down</b><p>Move the selected field down <b>one</b> position in the list.</p></html>");

    final JLabel moveUpButton = new JLabel(moveUp);
    moveUpButton.setOpaque(false);
    moveUpButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            moveUpButton.setIcon(moveUpOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            moveUpButton.setIcon(moveUp);
        }

        public void mousePressed(MouseEvent event) {
            moveUpButton.setIcon(moveUp);
            if (elementList.getSelectedIndex() != -1) {
                int toMoveUp = elementList.getSelectedIndex();

                if (toMoveUp != 0) {
                    swapElements(elementList, elementModel, toMoveUp, toMoveUp - 1);
                }

                updateFieldOrder();
                validateFormOrTable(ApplicationManager.getCurrentMappingObject());

            }
        }

    });

    moveUpButton.setToolTipText(
            "<html><b>Move Field Up</b><p>Move the selected field up <b>one</b> position in the list.</p></html>");

    buttonPanel.add(addFieldButton);
    buttonPanel.add(removeElementButton);
    buttonPanel.add(moveDownButton);
    buttonPanel.add(moveUpButton);

    container.add(buttonPanel);

    container.add(Box.createVerticalGlue());

    return container;
}

From source file:org.isatools.isacreatorconfigurator.configui.FieldInterface.java

private void instantiateFields(String initFieldName) {
    // OVERALL CONTAINER
    JPanel container = new JPanel();
    container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));
    container.setBackground(UIHelper.BG_COLOR);

    JLabel fieldDefinitionLab = new JLabel(fieldDefinitionHeader, JLabel.CENTER);
    container.add(fieldDefinitionLab);//from w  w w .j av  a 2s.c o  m

    container.add(Box.createVerticalStrut(5));

    // FIELD LABEL & INPUT BOX CONTAINER
    JPanel fieldCont = new JPanel(new GridLayout(1, 2));
    fieldCont.setBackground(UIHelper.BG_COLOR);

    fieldName = new RoundedJTextField(15);
    fieldName.setText(initFieldName);
    fieldName.setEditable(false);
    UIHelper.renderComponent(fieldName, UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, false);

    JLabel fieldNameLab = UIHelper.createLabel("Field Name: ", UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR);
    fieldCont.add(fieldNameLab);
    fieldCont.add(fieldName);
    container.add(fieldCont);

    JPanel descCont = new JPanel(new GridLayout(1, 2));
    descCont.setBackground(UIHelper.BG_COLOR);
    description = new RoundedJTextArea();
    description.setLineWrap(true);
    description.setWrapStyleWord(true);
    UIHelper.renderComponent(description, UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, false);

    JScrollPane descScroll = new JScrollPane(description, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    descScroll.setBackground(UIHelper.BG_COLOR);
    descScroll.setPreferredSize(new Dimension(150, 65));
    descScroll.getViewport().setBackground(UIHelper.BG_COLOR);

    IAppWidgetFactory.makeIAppScrollPane(descScroll);

    JLabel descLab = UIHelper.createLabel("Description: ", UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR);
    descLab.setVerticalAlignment(JLabel.TOP);
    descCont.add(descLab);
    descCont.add(descScroll);
    container.add(descCont);

    // add datatype information
    JPanel datatypeCont = new JPanel(new GridLayout(1, 2));
    datatypeCont.setBackground(UIHelper.BG_COLOR);

    DataTypes[] allowedDataTypes = initFieldName.equals(UNIT_STR) ? new DataTypes[] { DataTypes.ONTOLOGY_TERM }
            : DataTypes.values();

    datatype = new JComboBox(allowedDataTypes);
    datatype.addActionListener(this);
    UIHelper.renderComponent(datatype, UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, UIHelper.BG_COLOR);

    JLabel dataTypeLab = UIHelper.createLabel("Datatype:", UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR);
    datatypeCont.add(dataTypeLab);
    datatypeCont.add(datatype);
    container.add(datatypeCont);

    defaultValContStd = new JPanel(new GridLayout(1, 2));
    defaultValContStd.setBackground(UIHelper.BG_COLOR);

    defaultValCont = Box.createHorizontalBox();
    defaultValCont.setPreferredSize(new Dimension(150, 25));

    defaultValStd = new RoundedFormattedTextField(null, UIHelper.TRANSPARENT_LIGHT_GREEN_COLOR,
            UIHelper.DARK_GREEN_COLOR);
    defaultValCont.setPreferredSize(new Dimension(120, 25));
    defaultValStd.setFormatterFactory(new DefaultFormatterFactory(
            new RegExFormatter(".*", defaultValStd, false, UIHelper.DARK_GREEN_COLOR, UIHelper.RED_COLOR,
                    UIHelper.TRANSPARENT_LIGHT_GREEN_COLOR, UIHelper.TRANSPARENT_LIGHT_GREEN_COLOR)));
    defaultValStd.setForeground(UIHelper.DARK_GREEN_COLOR);
    defaultValStd.setFont(UIHelper.VER_11_PLAIN);

    defaultValCont.add(defaultValStd);

    defaultValLabStd = UIHelper.createLabel(DEFAULT_VAL_STR, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR);

    defaultValContStd.add(defaultValLabStd);
    defaultValContStd.add(defaultValCont);
    container.add(defaultValContStd);

    defaultValContBool = new JPanel(new GridLayout(1, 2));
    defaultValContBool.setBackground(UIHelper.BG_COLOR);
    defaultValContBool.setVisible(false);

    listDataSourceCont = new JPanel(new GridLayout(2, 1));
    listDataSourceCont.setBackground(UIHelper.BG_COLOR);
    listDataSourceCont.setVisible(false);

    JLabel listValLab = UIHelper.createLabel("Please enter comma separated list of values:",
            UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR);
    listDataSourceCont.add(listValLab);

    listValues = new RoundedJTextArea("SampleVal1, SampleVal2, SampleVal3", 3, 5);
    listValues.setLineWrap(true);
    listValues.setWrapStyleWord(true);
    UIHelper.renderComponent(listValues, UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, false);

    JScrollPane listScroll = new JScrollPane(listValues, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    listScroll.setBackground(UIHelper.BG_COLOR);
    listScroll.getViewport().setBackground(UIHelper.BG_COLOR);

    listDataSourceCont.add(listScroll);
    container.add(listDataSourceCont);

    IAppWidgetFactory.makeIAppScrollPane(listScroll);

    sourceEntryPanel = new JPanel(new BorderLayout());
    sourceEntryPanel.setSize(new Dimension(125, 190));
    sourceEntryPanel.setOpaque(false);
    sourceEntryPanel.setVisible(false);

    preferredOntologySource = new JPanel();
    preferredOntologySource.setLayout(new BoxLayout(preferredOntologySource, BoxLayout.PAGE_AXIS));
    preferredOntologySource.setVisible(false);
    recommendOntologySource = new JCheckBox("Use recommended ontology source?", false);

    UIHelper.renderComponent(recommendOntologySource, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    recommendOntologySource.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (recommendOntologySource.isSelected()) {
                sourceEntryPanel.setVisible(true);
            } else {
                sourceEntryPanel.setVisible(false);
            }
        }
    });

    JPanel useOntologySourceCont = new JPanel(new GridLayout(1, 1));
    useOntologySourceCont.add(recommendOntologySource);

    preferredOntologySource.add(useOntologySourceCont);

    JPanel infoCont = new JPanel(new GridLayout(1, 1));
    JLabel infoLab = UIHelper.createLabel(
            "<html>click on the <strong>configure ontologies</strong> button to open the ontology configurator to edit the list of ontologies and search areas within an ontology</html>",
            UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR);
    infoLab.setPreferredSize(new Dimension(100, 40));
    infoCont.add(infoLab);

    sourceEntryPanel.add(infoCont, BorderLayout.NORTH);

    JLabel preferredOntologiesLab = new JLabel(preferredOntologiesSidePanelIcon);
    preferredOntologiesLab.setVerticalAlignment(SwingConstants.TOP);

    sourceEntryPanel.add(preferredOntologiesLab, BorderLayout.WEST);

    ontologiesToUseModel = new DefaultTableModel(new String[0][2], ontologyColumnHeaders) {
        @Override
        public boolean isCellEditable(int i, int i1) {
            return false;
        }
    };
    ontologiesToUse = new JTable(ontologiesToUseModel);
    ontologiesToUse.getTableHeader().setBackground(UIHelper.BG_COLOR);

    try {
        ontologiesToUse.setDefaultRenderer(Class.forName("java.lang.Object"),
                new CustomSpreadsheetCellRenderer());
    } catch (ClassNotFoundException e) {
        // empty
    }

    renderTableHeader();

    JScrollPane ontologiesToUseScroller = new JScrollPane(ontologiesToUse,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    ontologiesToUseScroller.setBorder(new EmptyBorder(0, 0, 0, 0));
    ontologiesToUseScroller.setPreferredSize(new Dimension(100, 80));
    ontologiesToUseScroller.setBackground(UIHelper.BG_COLOR);
    ontologiesToUseScroller.getViewport().setBackground(UIHelper.BG_COLOR);

    IAppWidgetFactory.makeIAppScrollPane(ontologiesToUseScroller);

    sourceEntryPanel.add(ontologiesToUseScroller);

    JPanel buttonCont = new JPanel(new BorderLayout());
    final JLabel openConfigButton = new JLabel(ontologyConfigIcon);
    openConfigButton.setVerticalAlignment(SwingConstants.TOP);
    openConfigButton.setHorizontalAlignment(SwingConstants.RIGHT);

    MouseAdapter showOntologyConfigurator = new MouseAdapter() {

        public void mouseEntered(MouseEvent mouseEvent) {
            openConfigButton.setIcon(ontologyConfigIconOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            openConfigButton.setIcon(ontologyConfigIcon);
        }

        public void mousePressed(MouseEvent mouseEvent) {

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    if (openConfigButton.isEnabled()) {
                        openConfigButton.setIcon(ontologyConfigIcon);
                        ontologyConfig = new OntologyConfigUI(ontologiesToQuery, selectedOntologies);
                        ontologyConfig.addPropertyChangeListener("ontologySelected",
                                new PropertyChangeListener() {
                                    public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
                                        selectedOntologies = (ListOrderedMap<String, RecommendedOntology>) propertyChangeEvent
                                                .getNewValue();
                                        updateTable();
                                    }
                                });
                        showPopupInCenter(ontologyConfig);
                    }
                }
            });
        }

    };

    openConfigButton.addMouseListener(showOntologyConfigurator);

    buttonCont.add(openConfigButton, BorderLayout.EAST);

    sourceEntryPanel.add(buttonCont, BorderLayout.SOUTH);
    preferredOntologySource.add(sourceEntryPanel);
    container.add(preferredOntologySource);

    String[] contents = new String[] { "true", "false" };
    defaultValBool = new

    JComboBox(contents);

    UIHelper.renderComponent(defaultValBool, UIHelper.VER_12_PLAIN, UIHelper.DARK_GREEN_COLOR,
            UIHelper.BG_COLOR);

    JLabel defaultValLabBool = UIHelper.createLabel(DEFAULT_VAL_STR, UIHelper.VER_12_BOLD,
            UIHelper.DARK_GREEN_COLOR);

    defaultValContBool.add(defaultValLabBool);
    defaultValContBool.add(defaultValBool);
    container.add(defaultValContBool);

    // RegExp data entry
    isInputFormatted = new JCheckBox("Is the input formatted?", false);
    isInputFormatted.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    isInputFormatted.setHorizontalAlignment(SwingConstants.LEFT);

    UIHelper.renderComponent(isInputFormatted, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    isInputFormatted.addActionListener(this);
    container.add(UIHelper.wrapComponentInPanel(isInputFormatted));

    inputFormatCont = new JPanel();

    inputFormatCont.setLayout(new BoxLayout(inputFormatCont, BoxLayout.LINE_AXIS));
    inputFormatCont.setVisible(false);
    inputFormatCont.setBackground(UIHelper.BG_COLOR);
    inputFormat = new RoundedJTextField(10);
    inputFormat.setText(".*");
    inputFormat.setSize(new Dimension(150, 19));

    inputFormat.setPreferredSize(new Dimension(160, 25));
    inputFormat.setToolTipText("Field expects a regular expression describing the input format.");
    UIHelper.renderComponent(inputFormat, UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, false);

    JLabel inputFormatLab = UIHelper.createLabel("Input format:", UIHelper.VER_11_BOLD,
            UIHelper.DARK_GREEN_COLOR);
    inputFormatLab.setVerticalAlignment(SwingConstants.TOP);

    inputFormatCont.add(inputFormatLab);
    inputFormatCont.add(inputFormat);
    JLabel checkRegExp = new JLabel(checkRegExIcon, JLabel.RIGHT);
    checkRegExp.setOpaque(false);
    checkRegExp.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            String regexToCheck = inputFormat.getText();

            final CheckRegExGUI regexChecker = new CheckRegExGUI(regexToCheck);
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    regexChecker.createGUI();
                }
            });
            regexChecker.addPropertyChangeListener("close", new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    main.getApplicationContainer().hideSheet();
                }
            });
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    main.getApplicationContainer().showJDialogAsSheet(regexChecker);
                }
            });
        }

    }

    );
    inputFormatCont.add(checkRegExp);
    container.add(inputFormatCont);

    usesTemplateForWizard = new JCheckBox("Requires template for wizard?", false);
    usesTemplateForWizard.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    usesTemplateForWizard.setHorizontalAlignment(SwingConstants.LEFT);

    UIHelper.renderComponent(usesTemplateForWizard, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    usesTemplateForWizard.addActionListener(this);
    container.add(UIHelper.wrapComponentInPanel(usesTemplateForWizard));

    wizardTemplatePanel = new JPanel(new GridLayout(1, 2));
    wizardTemplatePanel.setVisible(false);
    wizardTemplatePanel.setBackground(UIHelper.BG_COLOR);

    wizardTemplate = new RoundedJTextArea();
    wizardTemplate.setToolTipText("A template for the wizard to auto-create the data...");
    wizardTemplate.setLineWrap(true);
    wizardTemplate.setWrapStyleWord(true);
    UIHelper.renderComponent(wizardTemplate, UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, false);

    JScrollPane wizScroll = new JScrollPane(wizardTemplate, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    wizScroll.getViewport().setBackground(UIHelper.BG_COLOR);
    wizScroll.setPreferredSize(new Dimension(70, 60));

    IAppWidgetFactory.makeIAppScrollPane(wizScroll);

    JLabel wizardTemplateLab = UIHelper.createLabel("Template definition:", UIHelper.VER_11_BOLD,
            UIHelper.DARK_GREEN_COLOR);
    wizardTemplateLab.setVerticalAlignment(JLabel.TOP);

    wizardTemplatePanel.add(wizardTemplateLab);
    wizardTemplatePanel.add(wizScroll);

    container.add(wizardTemplatePanel);

    JPanel checkCont = new JPanel(new GridLayout(3, 2));
    checkCont.setBackground(UIHelper.BG_COLOR);
    checkCont.setBorder(new TitledBorder(new RoundedBorder(UIHelper.DARK_GREEN_COLOR, 4),
            "Behavioural Attributes", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
            UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR));

    required = new JCheckBox("Required ", true);

    UIHelper.renderComponent(required, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    checkCont.add(required);

    acceptsMultipleValues = new JCheckBox("Allow multiple instances", false);

    UIHelper.renderComponent(acceptsMultipleValues, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    checkCont.add(acceptsMultipleValues);
    acceptsFileLocations = new JCheckBox("Accepts file locations", false);

    acceptsFileLocations.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            acceptsMultipleValues.setSelected(false);
            acceptsMultipleValues.setEnabled(!acceptsFileLocations.isSelected());
        }
    });

    UIHelper.renderComponent(acceptsFileLocations, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    checkCont.add(acceptsFileLocations);

    hidden = new JCheckBox("hidden?", false);

    UIHelper.renderComponent(hidden, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    checkCont.add(hidden);

    forceOntologySelection = new JCheckBox("Force ontology selection", false);
    UIHelper.renderComponent(forceOntologySelection, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);

    checkCont.add(forceOntologySelection);

    container.add(checkCont);

    JScrollPane contScroll = new JScrollPane(container, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    contScroll.setBorder(null);
    contScroll.setAutoscrolls(true);

    IAppWidgetFactory.makeIAppScrollPane(contScroll);

    add(contScroll, BorderLayout.NORTH);
}

From source file:org.jdal.swing.ListPane.java

public void init() {
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
    tableIcon = FormUtils.getIcon(tableIcon, DEFAULT_TABLE_ICON);
    for (PanelHolder p : panels)
        p.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));

    list = new JList(new ListListModel(panels));
    list.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setVisibleRowCount(-1);// w w  w.  java2  s. co  m
    list.addListSelectionListener(this);
    list.setCellRenderer(renderer);
    list.setSelectedIndex(0);

    if (cellHeight != 0)
        list.setFixedCellHeight(cellHeight);

    JScrollPane scroll = new JScrollPane(list);
    split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scroll, editorPanel);
    split.setResizeWeight(0);
    split.setDividerLocation(150);
    add(split);
}

From source file:org.opendatakit.briefcase.ui.ScrollingStatusListDialog.java

private ScrollingStatusListDialog(Frame frame, String title, IFormDefinition form, String statusHtml) {
    super(frame, title + form.getFormName(), true);
    this.form = form;
    AnnotationProcessor.process(this);
    // Create and initialize the buttons.
    JButton cancelButton = new JButton("Close");
    cancelButton.addActionListener(this);
    getRootPane().setDefaultButton(cancelButton);

    editorArea = new JEditorPane("text/plain", statusHtml);
    editorArea.setEditable(false);//w w w  .j a v  a  2 s . c o m
    //Put the editor pane in a scroll pane.
    JScrollPane editorScrollPane = new JScrollPane(editorArea);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setPreferredSize(new Dimension(400, 300));
    editorScrollPane.setMinimumSize(new Dimension(10, 10));

    // Create a container so that we can add a title around
    // the scroll pane. Can't add a title directly to the
    // scroll pane because its background would be white.
    // Lay out the label and scroll pane from top to bottom.
    JPanel listPane = new JPanel();
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
    listPane.add(Box.createRigidArea(new Dimension(0, 5)));
    listPane.add(editorScrollPane);
    listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    // Lay out the buttons from left to right.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(cancelButton);

    // Put everything together, using the content pane's BorderLayout.
    Container contentPane = getContentPane();
    contentPane.add(listPane, BorderLayout.CENTER);
    contentPane.add(buttonPane, BorderLayout.PAGE_END);

    // Initialize values.
    pack();
    setLocationRelativeTo(null);
}

From source file:org.pdfsam.guiclient.commons.panels.JVisualPdfPageSelectionPanel.java

/**
 * panel initialization/*from ww  w. ja  va  2  s .c  o  m*/
 */
private void init() {
    setLayout(new GridBagLayout());

    thumbnailList.setDrawDeletedItems(drawDeletedItems);
    if (dndSupport == DND_SUPPORT_FILES) {
        thumbnailList.setTransferHandler(new VisualListExportTransferHandler(pdfLoader));
    } else if (dndSupport == DND_SUPPORT_JAVAOBJECTS) {
        thumbnailList.setTransferHandler(new VisualListTransferHandler());
    } else if (dndSupport == DND_SUPPORT_FILES_AND_JAVAOBJECTS) {
        thumbnailList.setTransferHandler(new VisualListTransferHandler(pdfLoader));
    } else {
        thumbnailList.setTransferHandler(new VisualListExportTransferHandler(null));
    }
    thumbnailList.setDragEnabled(true);
    thumbnailList.setDropMode(DropMode.INSERT);
    pagesWorker = new PagesWorker(thumbnailList);
    thumbnailList.addKeyListener(new VisualPdfSelectionKeyAdapter(pagesWorker));
    thumbnailList.addMouseListener(new PageOpenerMouseAdapter(thumbnailList));

    if (showButtonPanel) {
        initButtonPanel(pagesWorker);
        initKeyListener();
    }

    //JList orientation
    if (HORIZONTAL_ORIENTATION == orientation) {
        thumbnailList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    } else {
        if (wrap) {
            thumbnailList.setLayoutOrientation(JList.VERTICAL_WRAP);
        }
    }

    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.LINE_AXIS));
    topPanel.setPreferredSize(new Dimension(400, 30));

    pdfSelectionActionListener = new VisualPdfSelectionActionListener(this, pdfLoader);
    if (topPanelStyle >= STYLE_TOP_PANEL_FULL) {
        //load button
        loadFileButton.setMargin(new Insets(1, 1, 1, 1));
        loadFileButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Open"));
        loadFileButton.setPreferredSize(new Dimension(100, 30));
        loadFileButton
                .setToolTipText(GettextResource.gettext(config.getI18nResourceBundle(), "Load a pdf document"));
        loadFileButton.setIcon(new ImageIcon(this.getClass().getResource("/images/add.png")));
        loadFileButton.addKeyListener(new EnterDoClickListener(loadFileButton));
        loadFileButton.setAlignmentX(Component.CENTER_ALIGNMENT);
        loadFileButton.setAlignmentY(Component.CENTER_ALIGNMENT);
        loadFileButton.setActionCommand(VisualPdfSelectionActionListener.ADD);
        loadFileButton.addActionListener(pdfSelectionActionListener);
    }
    documentProperties.setIcon(new ImageIcon(this.getClass().getResource("/images/info.png")));
    documentProperties.setVisible(false);

    if (topPanelStyle >= STYLE_TOP_PANEL_MEDIUM) {
        clearButton.setMargin(new Insets(1, 1, 1, 1));
        clearButton.setMinimumSize(new Dimension(30, 30));
        clearButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Clear"));
        clearButton.setIcon(new ImageIcon(this.getClass().getResource("/images/clear.png")));
        clearButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                resetPanel();
            }
        });
    }

    zoomInButton.setMargin(new Insets(1, 1, 1, 1));
    zoomInButton.setMinimumSize(new Dimension(30, 30));
    zoomInButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Zoom in"));
    zoomInButton.setIcon(new ImageIcon(this.getClass().getResource("/images/zoomin.png")));
    zoomInButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                thumbnailList.incZoomLevel();
                zoomOutButton.setEnabled(true);
                if (thumbnailList.getCurrentZoomLevel() >= JVisualSelectionList.MAX_ZOOM_LEVEL) {
                    zoomInButton.setEnabled(false);
                }
                ((VisualListModel) thumbnailList.getModel()).elementsChanged();
            } catch (Exception ex) {
                log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error setting zoom level."),
                        ex);
            }
        }
    });

    zoomOutButton.setMargin(new Insets(1, 1, 1, 1));
    zoomOutButton.setMinimumSize(new Dimension(30, 30));
    zoomOutButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Zoom out"));
    zoomOutButton.setIcon(new ImageIcon(this.getClass().getResource("/images/zoomout.png")));
    zoomOutButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                thumbnailList.deincZoomLevel();
                zoomInButton.setEnabled(true);
                if (thumbnailList.getCurrentZoomLevel() <= JVisualSelectionList.MIN_ZOOM_LEVEL) {
                    zoomOutButton.setEnabled(false);
                }
                ((VisualListModel) thumbnailList.getModel()).elementsChanged();
            } catch (Exception ex) {
                log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error setting zoom level."),
                        ex);
            }
        }
    });

    thumbnailList.setModel(new VisualListModel());
    thumbnailList.setCellRenderer(new VisualListRenderer());
    thumbnailList.setVisibleRowCount(-1);
    thumbnailList.setSelectionMode(selectionType);
    JScrollPane listScroller = new JScrollPane(thumbnailList);

    //preview item   
    menuItemPreview.setIcon(new ImageIcon(this.getClass().getResource("/images/preview-viewer.png")));
    menuItemPreview.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Preview"));
    menuItemPreview.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            int[] selection = thumbnailList.getSelectedIndices();
            if (selection != null && selection.length == 1) {
                VisualPageListItem item = (VisualPageListItem) thumbnailList.getModel()
                        .getElementAt(selection[0]);
                PagePreviewOpener.getInstance().openPreview(item.getParentFileCanonicalPath(),
                        item.getDocumentPassword(), item.getPageNumber());
            }
        }
    });

    if (showContextMenu) {
        //popup
        final JMenuItem menuItemMoveUp = new JMenuItem();
        menuItemMoveUp.setIcon(new ImageIcon(this.getClass().getResource("/images/up.png")));
        menuItemMoveUp.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Move Up"));
        menuItemMoveUp.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.MOVE_UP, pagesWorker));
        popupMenu.add(menuItemMoveUp);

        final JMenuItem menuItemMoveDown = new JMenuItem();
        menuItemMoveDown.setIcon(new ImageIcon(this.getClass().getResource("/images/down.png")));
        menuItemMoveDown.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Move Down"));
        menuItemMoveDown
                .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.MOVE_DOWN, pagesWorker));
        popupMenu.add(menuItemMoveDown);

        final JMenuItem menuItemRemove = new JMenuItem();
        menuItemRemove.setIcon(new ImageIcon(this.getClass().getResource("/images/remove.png")));
        menuItemRemove.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Delete"));
        menuItemRemove.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.REMOVE, pagesWorker));
        popupMenu.add(menuItemRemove);

        //if elements are physically deleted i don't need this item
        if (drawDeletedItems) {
            final JMenuItem menuItemUndelete = new JMenuItem();
            menuItemUndelete.setIcon(new ImageIcon(this.getClass().getResource("/images/remove.png")));
            menuItemUndelete.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Undelete"));
            menuItemUndelete
                    .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.UNDELETE, pagesWorker));
            popupMenu.add(menuItemUndelete);
        }

        //rotate item   
        final JMenuItem menuItemRotate = new JMenuItem();
        menuItemRotate.setIcon(new ImageIcon(this.getClass().getResource("/images/clockwise.png")));
        menuItemRotate.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Rotate clockwise"));
        menuItemRotate
                .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.ROTATE_CLOCK, pagesWorker));
        popupMenu.add(menuItemRotate);

        //rotate anticlock item   
        final JMenuItem menuItemAntiRotate = new JMenuItem();
        menuItemAntiRotate.setIcon(new ImageIcon(this.getClass().getResource("/images/anticlockwise.png")));
        menuItemAntiRotate
                .setText(GettextResource.gettext(config.getI18nResourceBundle(), "Rotate anticlockwise"));
        menuItemAntiRotate.addMouseListener(
                new VisualPdfSelectionMouseAdapter(PagesWorker.ROTATE_ANTICLOCK, pagesWorker));
        popupMenu.add(menuItemAntiRotate);

        //reverse item   
        final JMenuItem menuItemReverse = new JMenuItem();
        menuItemReverse.setIcon(new ImageIcon(this.getClass().getResource("/images/reverse.png")));
        menuItemReverse.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Reverse"));
        menuItemReverse.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.REVERSE, pagesWorker));
        popupMenu.add(menuItemReverse);

        enableSetOutputPathMenuItem();

        addPopupShower();
    }

    popupMenu.add(menuItemPreview);

    if (topPanelStyle >= STYLE_TOP_PANEL_FULL) {
        topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
        topPanel.add(loadFileButton);
    }
    if (topPanelStyle >= STYLE_TOP_PANEL_MEDIUM) {
        topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
        topPanel.add(clearButton);
    }
    topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    topPanel.add(documentProperties);
    topPanel.add(Box.createHorizontalGlue());
    topPanel.add(zoomInButton);
    topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    topPanel.add(zoomOutButton);

    GridBagConstraints topConstraints = new GridBagConstraints();
    topConstraints.fill = GridBagConstraints.BOTH;
    topConstraints.gridx = 0;
    topConstraints.gridy = 0;
    topConstraints.gridwidth = 3;
    topConstraints.gridheight = 1;
    topConstraints.insets = new Insets(5, 5, 5, 5);
    topConstraints.weightx = 1.0;
    topConstraints.weighty = 0.0;
    if (topPanelStyle > STYLE_TOP_PANEL_HIDE) {
        add(topPanel, topConstraints);
    }

    GridBagConstraints thumbConstraints = new GridBagConstraints();
    thumbConstraints.fill = GridBagConstraints.BOTH;
    thumbConstraints.gridx = 0;
    thumbConstraints.gridy = 1;
    thumbConstraints.gridwidth = (showButtonPanel ? 2 : 3);
    thumbConstraints.gridheight = 2;
    thumbConstraints.insets = new Insets(5, 5, 5, 5);
    thumbConstraints.weightx = 1.0;
    thumbConstraints.weighty = 1.0;
    add(listScroller, thumbConstraints);

    if (showButtonPanel) {
        GridBagConstraints buttonsConstraints = new GridBagConstraints();
        buttonsConstraints.fill = GridBagConstraints.BOTH;
        buttonsConstraints.gridx = 2;
        buttonsConstraints.gridy = 1;
        buttonsConstraints.gridwidth = 1;
        buttonsConstraints.gridheight = 2;
        buttonsConstraints.insets = new Insets(5, 5, 5, 5);
        buttonsConstraints.weightx = 0.0;
        buttonsConstraints.weighty = 1.0;
        add(buttonPanel, buttonsConstraints);
    }
}