Example usage for javax.swing JComponent setBorder

List of usage examples for javax.swing JComponent setBorder

Introduction

In this page you can find the example usage for javax.swing JComponent setBorder.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.")
public void setBorder(Border border) 

Source Link

Document

Sets the border of this component.

Usage

From source file:org.codinjutsu.tools.nosql.couchbase.view.CouchbasePanel.java

protected void addCommonsActions() {
    final TreeExpander treeExpander = new TreeExpander() {
        @Override/*w  w w  .  ja v a 2  s .c  o  m*/
        public void expandAll() {
            CouchbasePanel.this.expandAll();
        }

        @Override
        public boolean canExpand() {
            return true;
        }

        @Override
        public void collapseAll() {
            CouchbasePanel.this.collapseAll();
        }

        @Override
        public boolean canCollapse() {
            return true;
        }
    };

    CommonActionsManager actionsManager = CommonActionsManager.getInstance();

    final AnAction expandAllAction = actionsManager.createExpandAllAction(treeExpander, resultPanel);
    final AnAction collapseAllAction = actionsManager.createCollapseAllAction(treeExpander, resultPanel);

    Disposer.register(this, new Disposable() {
        @Override
        public void dispose() {
            collapseAllAction.unregisterCustomShortcutSet(resultPanel);
            expandAllAction.unregisterCustomShortcutSet(resultPanel);
        }
    });

    DefaultActionGroup actionResultGroup = new DefaultActionGroup("CouchbaseResultGroup", true);
    actionResultGroup.add(new ExecuteQuery<>(this));
    actionResultGroup.addSeparator();
    actionResultGroup.add(expandAllAction);
    actionResultGroup.add(collapseAllAction);

    ActionToolbar actionToolBar = ActionManager.getInstance().createActionToolbar("CouchbaseResultGroupActions",
            actionResultGroup, true);
    actionToolBar.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    JComponent actionToolBarComponent = actionToolBar.getComponent();
    actionToolBarComponent.setBorder(null);
    actionToolBarComponent.setOpaque(false);

    toolBarPanel.add(actionToolBarComponent, BorderLayout.CENTER);
}

From source file:org.codinjutsu.tools.nosql.redis.view.RedisPanel.java

protected void addCommonsActions() {
    final TreeExpander treeExpander = new TreeExpander() {
        @Override// w  ww.j a  va 2s .  co  m
        public void expandAll() {
            RedisPanel.this.expandAll();
        }

        @Override
        public boolean canExpand() {
            return true;
        }

        @Override
        public void collapseAll() {
            RedisPanel.this.collapseAll();
        }

        @Override
        public boolean canCollapse() {
            return true;
        }
    };

    CommonActionsManager actionsManager = CommonActionsManager.getInstance();

    final AnAction expandAllAction = actionsManager.createExpandAllAction(treeExpander, resultPanel);
    final AnAction collapseAllAction = actionsManager.createCollapseAllAction(treeExpander, resultPanel);

    Disposer.register(this, new Disposable() {
        @Override
        public void dispose() {
            collapseAllAction.unregisterCustomShortcutSet(resultPanel);
            expandAllAction.unregisterCustomShortcutSet(resultPanel);
        }
    });

    DefaultActionGroup actionResultGroup = new DefaultActionGroup("RedisResultGroup", true);
    actionResultGroup.add(new ExecuteQuery<>(this));
    actionResultGroup.addSeparator();
    actionResultGroup.add(new EnableGroupingAction(this));
    actionResultGroup.add(new SetSeparatorAction(this));
    actionResultGroup.addSeparator();
    actionResultGroup.add(expandAllAction);
    actionResultGroup.add(collapseAllAction);

    ActionToolbar actionToolBar = ActionManager.getInstance().createActionToolbar("MongoResultGroupActions",
            actionResultGroup, true);
    actionToolBar.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    JComponent actionToolBarComponent = actionToolBar.getComponent();
    actionToolBarComponent.setBorder(null);
    actionToolBarComponent.setOpaque(false);

    toolBarPanel.add(actionToolBarComponent, BorderLayout.CENTER);
}

From source file:org.drugis.addis.gui.WelcomeDialog.java

private void setBorder(JComponent pane) {
    pane.setPreferredSize(new Dimension(TEXT_WIDTH, COMP_HEIGHT));
    pane.setBorder(ETCHED_BORDER);
    pane.setBackground(Color.white);
}

From source file:org.isatools.isacreator.gui.DataEntryForm.java

/**
 * Adds the fields describing a section to a Container (e.g. JPanel, Box, etc.)
 *
 * @param containerToAddTo @see JPanel, @see Box, @see  Container
 * @param sectionToAddTo   - @see InvestigationFileSection as a reference for where the fields are being added
 * @param fieldValues      - Map of field name to values.
 * @param referenceObject  - A @see DataEntryReferenceObject which gives information about
 *//* w  w  w .  j  a  va 2  s  . c  o m*/
public void addFieldsToPanel(Container containerToAddTo, InvestigationFileSection sectionToAddTo,
        OrderedMap<String, String> fieldValues, DataEntryReferenceObject referenceObject) {

    if (fieldDefinitions == null) {
        fieldDefinitions = new ListOrderedMap<String, JComponent>();
    }

    Set<String> ontologyFields = referenceObject.getOntologyTerms(sectionToAddTo);
    Set<String> fieldsToIgnore = referenceObject.getFieldsToIgnore();

    for (String fieldName : fieldValues.keySet()) {

        if (!fieldsToIgnore.contains(fieldName)) {
            FieldObject fieldDescriptor = referenceObject.getFieldDefinition(fieldName);

            if (!fieldDescriptor.isHidden()) {
                String tmpFieldName = fieldName;

                if (realNamesToAliases.containsKey(fieldName)) {
                    tmpFieldName = realNamesToAliases.get(fieldName);
                }

                JPanel fieldPanel = createFieldPanel(1, 2);
                JLabel fieldLabel = createLabel(tmpFieldName);

                JComponent textComponent;

                if (fieldDescriptor.getDatatype() == DataTypes.STRING
                        || fieldDescriptor.getDatatype() == DataTypes.ONTOLOGY_TERM
                        || fieldDescriptor.getDatatype() == DataTypes.DATE) {
                    textComponent = new RoundedJTextField(10);
                } else if (fieldDescriptor.getDatatype() == DataTypes.LONG_STRING) {
                    textComponent = new JTextArea();

                    ((JTextArea) textComponent).setSelectionColor(UIHelper.LIGHT_GREEN_COLOR);
                    ((JTextArea) textComponent).setSelectedTextColor(UIHelper.BG_COLOR);

                    ((JTextArea) textComponent).setWrapStyleWord(true);
                    ((JTextArea) textComponent).setLineWrap(true);
                    textComponent.setBackground(UIHelper.BG_COLOR);
                    textComponent.setBorder(UIHelper.GREEN_ROUNDED_BORDER);
                } else if (fieldDescriptor.getDatatype() == DataTypes.LIST) {
                    textComponent = new JComboBox(fieldDescriptor.getFieldList());
                } else {
                    textComponent = new RoundedJTextField(10);
                }

                if (textComponent instanceof JTextArea || textComponent instanceof JTextComponent) {
                    ((JTextComponent) textComponent)
                            .setText(fieldValues.get(fieldName).equals("") ? fieldDescriptor.getDefaultVal()
                                    : fieldValues.get(fieldName));
                }
                textComponent.setToolTipText(fieldDescriptor.getDescription());

                UIHelper.renderComponent(textComponent, UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR,
                        false);

                fieldPanel.add(fieldLabel);

                if (textComponent instanceof JTextArea) {

                    JScrollPane invDescScroll = new JScrollPane(textComponent,
                            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
                    invDescScroll.setPreferredSize(new Dimension(200, 75));

                    invDescScroll.getViewport().setBackground(UIHelper.BG_COLOR);

                    ((JTextArea) textComponent).getDocument().addDocumentListener(new DocumentChangeListener());

                    IAppWidgetFactory.makeIAppScrollPane(invDescScroll);
                    fieldPanel.add(
                            UIHelper.createTextEditEnableJTextArea(invDescScroll, (JTextArea) textComponent));
                } else if (textComponent instanceof JTextComponent) {

                    if (fieldDescriptor.getDatatype() == DataTypes.ONTOLOGY_TERM
                            || ontologyFields.contains(fieldName)) {
                        fieldPanel.add(createOntologyDropDown(fieldName, (JTextComponent) textComponent, true,
                                false, fieldDescriptor.getRecommmendedOntologySource()));
                    } else if (fieldDescriptor.getDatatype() == DataTypes.DATE) {
                        fieldPanel.add(createDateDropDown((JTextComponent) textComponent));
                    } else if (fieldDescriptor.isAcceptsFileLocations()) {
                        fieldPanel.add(createFileField((JTextComponent) textComponent));
                    } else {
                        fieldPanel.add(textComponent);
                    }
                    ((JTextComponent) textComponent).getDocument()
                            .addDocumentListener(new DocumentChangeListener());
                } else {
                    fieldPanel.add(textComponent);
                }

                fieldDefinitions.put(tmpFieldName, textComponent);

                containerToAddTo.add(fieldPanel);
                containerToAddTo.add(Box.createVerticalStrut(5));
            }
        }
    }
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Sets the defaults for the specified area.
 * /* w  w w.  j  a va  2 s.  c o  m*/
 * @param area The text area.
 */
public static void setTextAreaDefault(JComponent area) {
    if (area == null)
        return;
    area.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    //area.setForeground(STEELBLUE);
    area.setBackground(BACKGROUND);
    area.setOpaque(true);
    if (area instanceof JTextComponent)
        ((JTextComponent) area).setEditable(true);
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Formats and sets the title border of the passed component.
 * /* ww  w  .  j  av a 2  s .  c o  m*/
 * @param title The title.
 * @param p      The component to handle.
 */
public static void setBoldTitledBorder(String title, JComponent p) {
    if (title == null)
        title = "";
    if (p == null)
        return;
    TitledBorder border = new TitledBorder(title);
    border.setTitleFont(p.getFont().deriveFont(Font.BOLD));
    p.setBorder(border);
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Creates a new label.// w w  w .  j ava2  s.  c  o m
 * 
 * @param type    The type of component to create. Default type is JLabel.
 * @param color The foreground color if not <code>null</code>.
 * @return See above.
 */
public static JComponent createComponent(Class type, Color color) {
    if (type == null)
        type = JLabel.class;
    JComponent comp = null;
    if (JLabel.class.equals(type))
        comp = new JLabel();
    else if (OMETextField.class.equals(type))
        comp = new OMETextField();
    else if (OMETextArea.class.equals(type))
        comp = new OMETextArea();
    else if (NumericalTextField.class.equals(type)) {
        comp = new NumericalTextField();
        ((NumericalTextField) comp).setHorizontalAlignment(JTextField.LEFT);
        ((NumericalTextField) comp).setNegativeAccepted(true);
        comp.setBorder(null);
    }

    if (comp == null)
        comp = new JLabel();
    comp.setBackground(BACKGROUND_COLOR);
    Font font = comp.getFont();
    comp.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2));
    if (color != null)
        comp.setForeground(color);
    return comp;
}

From source file:org.revager.gui.findings_list.FindingsListFrame.java

private void markComponent(JComponent comp) {
    boolean mark = false;
    try {/*from w  ww. j a va 2s. c o m*/
        if (Data.getInstance().getAppData()
                .getSettingValue(AppSettingKey.APP_HIGHLIGHT_FIELDS) == AppSettingValue.TRUE) {
            mark = true;
        }
    } catch (DataException e) {
        mark = true;
    }

    if (!componentMarked && mark) {
        if (comp instanceof JTextField) {
            comp.setBorder(UI.MARKED_BORDER_INLINE);
        } else {
            comp.setBorder(UI.MARKED_BORDER);
        }
        componentMarked = true;
    }
}

From source file:org.springframework.richclient.factory.DefaultComponentFactory.java

public JComponent createTitledBorderFor(String labelKey, JComponent component) {
    component.setBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(getRequiredMessage(labelKey)),
                    GuiStandardUtils.createEvenlySpacedBorder(UIConstants.ONE_SPACE)));
    return component;
}

From source file:org.ut.biolab.medsavant.client.view.component.SearchableTablePanel.java

public SearchableTablePanel(String pageName, String[] columnNames, Class[] columnClasses, int[] hiddenColumns,
        boolean allowSearch, boolean allowSort, int defaultRows, boolean allowPages,
        TableSelectionType selectionType, int defaultRowsRetrieved, DataRetriever<Object[]> retriever) {

    this.pageName = pageName;
    this.rowsPerPageX = defaultRows;
    this.defaultRowsRetrieved = defaultRowsRetrieved;

    this.retriever = retriever;
    this.hiddenColumns = hiddenColumns;
    table = new SortableTable() {
        @Override//from ww  w . jav a2s .com
        public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
            synchronized (SearchableTablePanel.this) {
                JComponent comp = (JComponent) super.prepareRenderer(renderer, row, col);

                // Even index, selected or not selected
                if (isRowToggled(TableModelWrapperUtils.getActualRowAt(this.getSortableTableModel(), row))) { //this.getActualRowAt(this.getSortedRowAt(row)))) {
                    comp.setBackground(new Color(178, 225, 92));
                } else if (isCellSelected(row, col)) {
                    //comp.setBackground(new Color(75, 149, 229));
                    comp.setBackground(SELECTED_COLOUR);
                } else if (selectedRows != null
                        && selectedRows.contains(TableModelWrapperUtils.getActualRowAt(getModel(), row))) {
                    //comp.setBackground(SELECTED_COLOUR);
                } else if (row % 2 == 0 && !isCellSelected(row, col)) {
                    comp.setBackground(Color.WHITE);
                } else {
                    comp.setBackground(DARK_COLOUR);
                }

                comp.setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7));
                return comp;
            }
        }

        @Override
        public String getToolTipText(MouseEvent e) {
            return getToolTip(
                    TableModelWrapperUtils.getActualRowAt(table.getModel(), table.rowAtPoint(e.getPoint())));
        }
    };

    table.setToolTipText(""); //necessary to force check for tooltip text

    table.setClearSelectionOnTableDataChanges(true);
    table.setOptimized(true);
    table.setColumnAutoResizable(true);
    table.setAutoResort(false);
    table.setRowHeight(20);
    table.setSortable(allowSort);
    table.setSortingEnabled(allowSort);
    table.setFocusable(selectionType != TableSelectionType.DISABLED);
    //table.setCellSelectionEnabled(allowSelection);
    table.setCellSelectionEnabled(selectionType == TableSelectionType.CELL);
    table.setRowSelectionAllowed(selectionType == TableSelectionType.ROW);

    table.setAutoResizeMode(SortableTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

    //column chooser
    TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(table);
    installer.addTableHeaderPopupMenuCustomizer(new AutoResizePopupMenuCustomizer());
    columnChooser = new ColumnChooser(table);
    installer.addTableHeaderPopupMenuCustomizer(columnChooser);

    AutoFilterTableHeader header = new AutoFilterTableHeader(table);
    header.setAutoFilterEnabled(true);
    header.setShowFilterIcon(true);
    header.setShowFilterName(true);
    table.setTableHeader(header);

    filterField = new QuickTableFilterField(model);

    if (allowPages) {
        filterField.setHintText("Search for anything on the page");
    } else {
        filterField.setHintText("Search for anything");
    }

    setLayout(new BorderLayout(3, 3));
    fieldPanel = ViewUtil.getClearPanel();

    if (allowSearch) {
        fieldPanel.add(filterField);
    }

    chooseColumnButton = new JButton("Columns");
    chooseColumnButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            columnChooser.showDialog();
        }
    });

    helpButton = ViewUtil.getHelpButton("About Variant List",
            "Variants are sorted first by DNA ID, then by position.  The list of variants within each page can be sorted by various fields by clicking the corresponding column name, but note that this will only sort the current page.");
    exportButton = new JButton("Export");
    exportButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            try {
                ExportTable.exportTable(table);
            } catch (Exception ex) {
                LOG.error("Error while exporting.", ex);
                DialogUtils.displayException("MedSavant",
                        "<HTML>A problem occurred while exporting.<BR>Make sure the output file is not already in use.</HTML>",
                        ex);
            }
        }
    });

    fieldPanel.add(helpButton);
    fieldPanel.add(chooseColumnButton);
    fieldPanel.add(exportButton);

    bottomPanel = ViewUtil.getClearPanel();
    bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));

    gotoFirst = niceButton();
    gotoPrevious = niceButton();
    gotoNext = niceButton();
    gotoLast = niceButton();

    gotoFirst.setIcon(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.FIRST));
    gotoPrevious.setIcon(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.PREVIOUS));
    gotoNext.setIcon(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.NEXT));
    gotoLast.setIcon(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.LAST));

    gotoFirst.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            goToFirstPage();
        }
    });
    gotoPrevious.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            goToPreviousPage();
        }
    });
    gotoNext.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            goToNextPage();
        }
    });
    gotoLast.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            goToLastPage();
        }
    });

    pageText = new JTextField();
    ViewUtil.makeSmall(pageText);
    pageText.setColumns(5);
    pageText.setMaximumSize(new Dimension(50, 20));
    pageText.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key == KeyEvent.VK_ENTER) {
                try {
                    setPageNumber(Integer.parseInt(pageText.getText()));
                } catch (NumberFormatException ex) {
                    setPageNumber(0);
                }
            }
        }
    });

    amountLabel = new JLabel();
    ViewUtil.makeSmall(amountLabel);
    bottomPanel.add(amountLabel);

    pageLabel1 = new JLabel("Page ");
    ViewUtil.makeSmall(pageLabel1);
    pageLabel2 = new JLabel();
    ViewUtil.makeSmall(pageLabel2);

    bottomPanel.add(Box.createHorizontalGlue());
    bottomPanel.add(gotoFirst);
    bottomPanel.add(gotoPrevious);
    strut(bottomPanel);
    bottomPanel.add(pageLabel1);
    bottomPanel.add(pageText);
    bottomPanel.add(pageLabel2);
    strut(bottomPanel);
    bottomPanel.add(gotoNext);
    bottomPanel.add(gotoLast);
    bottomPanel.add(Box.createHorizontalGlue());

    strut(bottomPanel);

    JLabel perpageL = new JLabel("Per page:");
    ViewUtil.makeSmall(perpageL);
    bottomPanel.add(perpageL);

    strut(bottomPanel);

    boolean hasDefaultRowsPerPage = true;
    if (rowsPerPageX == ROWSPERPAGE_1 || rowsPerPageX == ROWSPERPAGE_2 || rowsPerPageX == ROWSPERPAGE_3) {
        hasDefaultRowsPerPage = false;
    }
    ArrayList<Integer> rowsList = new ArrayList<Integer>();
    rowsList.add(ROWSPERPAGE_1);
    rowsList.add(ROWSPERPAGE_2);
    rowsList.add(ROWSPERPAGE_3);
    Integer[] finalList = new Integer[3];
    if (hasDefaultRowsPerPage) {
        rowsList.add(rowsPerPageX);
        Collections.sort(rowsList);
    }
    finalList = rowsList.toArray(finalList);

    rowsPerPageDropdown = new JComboBox(finalList);
    ViewUtil.makeSmall(rowsPerPageDropdown);
    rowsPerPageDropdown.setPrototypeDisplayValue(ROWSPERPAGE_3);
    if (hasDefaultRowsPerPage) {
        rowsPerPageDropdown.setSelectedIndex(rowsList.indexOf(rowsPerPageX));
    } else {
        rowsPerPageDropdown.setSelectedIndex(1);
    }
    rowsPerPageDropdown.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            int rowsPerPage = (Integer) cb.getSelectedItem();
            setNumRowsPerPage(rowsPerPage);
        }
    });
    rowsPerPageDropdown.setPreferredSize(new Dimension(100, 25));
    rowsPerPageDropdown.setMaximumSize(new Dimension(100, 25));
    bottomPanel.add(rowsPerPageDropdown);

    setTableModel(data, columnNames, columnClasses);

    JPanel tablePanel = new JPanel(new BorderLayout(3, 3));
    JScrollPane jsp = new JScrollPane(table);
    jsp.setBorder(null);
    tablePanel.add(jsp);

    if (allowSort) {
        add(fieldPanel, BorderLayout.NORTH);
    }

    if (allowPages) {
        add(bottomPanel, BorderLayout.SOUTH);
    }

    add(tablePanel, BorderLayout.CENTER);

    initEmpty();
}