Example usage for javax.swing JScrollPane getBorder

List of usage examples for javax.swing JScrollPane getBorder

Introduction

In this page you can find the example usage for javax.swing JScrollPane getBorder.

Prototype

public Border getBorder() 

Source Link

Document

Returns the border of this component or null if no border is currently set.

Usage

From source file:Main.java

public static <T extends JComponent> JScrollPane wrap(final T component, final String title) {

    final JScrollPane scrollPane = new JScrollPane(component);
    scrollPane.setBorder(BorderFactory.createTitledBorder(scrollPane.getBorder(), title));
    return scrollPane;
}

From source file:KjellDirdalNotepad.java

public void setNormalSize() {
    JScrollPane scrollPane = getScrollPane();
    int x = 0;//from  ww  w .  j  ava 2  s .  c  o  m
    int y = 0;
    Insets scrollInsets = getScrollPaneInsets();

    if (scrollPane != null) {
        Dimension d = scrollPane.getVisibleRect().getSize();
        if (scrollPane.getBorder() != null) {
            d.setSize(d.getWidth() - scrollInsets.left - scrollInsets.right,
                    d.getHeight() - scrollInsets.top - scrollInsets.bottom);
        }

        d.setSize(d.getWidth() - 20, d.getHeight() - 20);
        desktop.setAllSize(x, y);
        scrollPane.invalidate();
        scrollPane.validate();
    }
}

From source file:com.floreantpos.ui.dialog.DiscountSelectionDialog.java

private void initComponent() {
    setOkButtonText(POSConstants.SAVE_BUTTON_TEXT);
    createCouponSearchPanel();/*from w  w  w  .j  a v  a 2 s .  c o m*/
    getContentPanel().add(itemSearchPanel, BorderLayout.NORTH);

    buttonsPanel = new ScrollableFlowPanel(FlowLayout.LEADING);

    JScrollPane scrollPane = new PosScrollPane(buttonsPanel, PosScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            PosScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(80, 0));
    scrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5),
            scrollPane.getBorder()));

    getContentPanel().add(scrollPane, BorderLayout.CENTER);

    rendererDiscounts();

    setSize(1024, 720);
}

From source file:com.projity.pm.graphic.chart.TimeChartPanel.java

public void configureScrollPaneHeaders(JScrollPane scrollPane, JComponent rowHeader) {
    viewport = scrollPane.getViewport();
    if (viewport == null || viewport.getView() != this)
        return;//from www  .  j ava2 s . c om

    JViewport vp = new JViewport();
    vp.setView(rowHeader);
    vp.setPreferredSize(rowHeader.getPreferredSize());
    scrollPane.setRowHeader(vp);

    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, new ChartCorner(this));

    Border border = scrollPane.getBorder();
    if (border == null || border instanceof UIResource) {
        scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
    }

    // left scale synchro
    viewport.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            updateTimeScaleComponentSize();
        }
    });

}

From source file:components.TextSamplerDemo.java

public TextSamplerDemo() {
    setLayout(new BorderLayout());

    //Create a regular text field.
    JTextField textField = new JTextField(10);
    textField.setActionCommand(textFieldString);
    textField.addActionListener(this);

    //Create a password field.
    JPasswordField passwordField = new JPasswordField(10);
    passwordField.setActionCommand(passwordFieldString);
    passwordField.addActionListener(this);

    //Create a formatted text field.
    JFormattedTextField ftf = new JFormattedTextField(java.util.Calendar.getInstance().getTime());
    ftf.setActionCommand(textFieldString);
    ftf.addActionListener(this);

    //Create some labels for the fields.
    JLabel textFieldLabel = new JLabel(textFieldString + ": ");
    textFieldLabel.setLabelFor(textField);
    JLabel passwordFieldLabel = new JLabel(passwordFieldString + ": ");
    passwordFieldLabel.setLabelFor(passwordField);
    JLabel ftfLabel = new JLabel(ftfString + ": ");
    ftfLabel.setLabelFor(ftf);/*from   ww  w  .ja  v a 2 s  .co  m*/

    //Create a label to put messages during an action event.
    actionLabel = new JLabel("Type text in a field and press Enter.");
    actionLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));

    //Lay out the text controls and the labels.
    JPanel textControlsPane = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    textControlsPane.setLayout(gridbag);

    JLabel[] labels = { textFieldLabel, passwordFieldLabel, ftfLabel };
    JTextField[] textFields = { textField, passwordField, ftf };
    addLabelTextRows(labels, textFields, gridbag, textControlsPane);

    c.gridwidth = GridBagConstraints.REMAINDER; //last
    c.anchor = GridBagConstraints.WEST;
    c.weightx = 1.0;
    textControlsPane.add(actionLabel, c);
    textControlsPane.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Text Fields"), BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Create a text area.
    JTextArea textArea = new JTextArea("This is an editable JTextArea. "
            + "A text area is a \"plain\" text component, " + "which means that although it can display text "
            + "in any font, all of the text is in the same font.");
    textArea.setFont(new Font("Serif", Font.ITALIC, 16));
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setPreferredSize(new Dimension(250, 250));
    areaScrollPane.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Plain Text"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5)),
            areaScrollPane.getBorder()));

    //Create an editor pane.
    JEditorPane editorPane = createEditorPane();
    JScrollPane editorScrollPane = new JScrollPane(editorPane);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setPreferredSize(new Dimension(250, 145));
    editorScrollPane.setMinimumSize(new Dimension(10, 10));

    //Create a text pane.
    JTextPane textPane = createTextPane();
    JScrollPane paneScrollPane = new JScrollPane(textPane);
    paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    paneScrollPane.setPreferredSize(new Dimension(250, 155));
    paneScrollPane.setMinimumSize(new Dimension(10, 10));

    //Put the editor pane and the text pane in a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, editorScrollPane, paneScrollPane);
    splitPane.setOneTouchExpandable(true);
    splitPane.setResizeWeight(0.5);
    JPanel rightPane = new JPanel(new GridLayout(1, 0));
    rightPane.add(splitPane);
    rightPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Styled Text"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Put everything together.
    JPanel leftPane = new JPanel(new BorderLayout());
    leftPane.add(textControlsPane, BorderLayout.PAGE_START);
    leftPane.add(areaScrollPane, BorderLayout.CENTER);

    add(leftPane, BorderLayout.LINE_START);
    add(rightPane, BorderLayout.LINE_END);
}

From source file:TextSamplerDemo.java

public TextSamplerDemo() {
    setLayout(new BorderLayout());

    //Create a regular text field.
    JTextField textField = new JTextField(10);
    textField.setActionCommand(textFieldString);
    textField.addActionListener(this);

    //Create a password field.
    JPasswordField passwordField = new JPasswordField(10);
    passwordField.setActionCommand(passwordFieldString);
    passwordField.addActionListener(this);

    //Create a formatted text field.
    JFormattedTextField ftf = new JFormattedTextField(java.util.Calendar.getInstance().getTime());
    ftf.setActionCommand(textFieldString);
    ftf.addActionListener(this);

    //Create some labels for the fields.
    JLabel textFieldLabel = new JLabel(textFieldString + ": ");
    textFieldLabel.setLabelFor(textField);
    JLabel passwordFieldLabel = new JLabel(passwordFieldString + ": ");
    passwordFieldLabel.setLabelFor(passwordField);
    JLabel ftfLabel = new JLabel(ftfString + ": ");
    ftfLabel.setLabelFor(ftf);//from   w  ww.  ja  v a  2 s.  co m

    //Create a label to put messages during an action event.
    actionLabel = new JLabel("Type text and then Enter in a field.");
    actionLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));

    //Lay out the text controls and the labels.
    JPanel textControlsPane = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    textControlsPane.setLayout(gridbag);

    JLabel[] labels = { textFieldLabel, passwordFieldLabel, ftfLabel };
    JTextField[] textFields = { textField, passwordField, ftf };
    addLabelTextRows(labels, textFields, gridbag, textControlsPane);

    c.gridwidth = GridBagConstraints.REMAINDER; //last
    c.anchor = GridBagConstraints.WEST;
    c.weightx = 1.0;
    textControlsPane.add(actionLabel, c);
    textControlsPane.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Text Fields"), BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Create a text area.
    JTextArea textArea = new JTextArea("This is an editable JTextArea. "
            + "A text area is a \"plain\" text component, " + "which means that although it can display text "
            + "in any font, all of the text is in the same font.");
    textArea.setFont(new Font("Serif", Font.ITALIC, 16));
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setPreferredSize(new Dimension(250, 250));
    areaScrollPane.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Plain Text"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5)),
            areaScrollPane.getBorder()));

    //Create an editor pane.
    JEditorPane editorPane = createEditorPane();
    JScrollPane editorScrollPane = new JScrollPane(editorPane);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setPreferredSize(new Dimension(250, 145));
    editorScrollPane.setMinimumSize(new Dimension(10, 10));

    //Create a text pane.
    JTextPane textPane = createTextPane();
    JScrollPane paneScrollPane = new JScrollPane(textPane);
    paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    paneScrollPane.setPreferredSize(new Dimension(250, 155));
    paneScrollPane.setMinimumSize(new Dimension(10, 10));

    //Put the editor pane and the text pane in a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, editorScrollPane, paneScrollPane);
    splitPane.setOneTouchExpandable(true);
    splitPane.setResizeWeight(0.5);
    JPanel rightPane = new JPanel(new GridLayout(1, 0));
    rightPane.add(splitPane);
    rightPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Styled Text"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Put everything together.
    JPanel leftPane = new JPanel(new BorderLayout());
    leftPane.add(textControlsPane, BorderLayout.PAGE_START);
    leftPane.add(areaScrollPane, BorderLayout.CENTER);

    add(leftPane, BorderLayout.LINE_START);
    add(rightPane, BorderLayout.LINE_END);
}

From source file:KjellDirdalNotepad.java

protected void resizeDesktop() {
    int x = 0;/*  w ww.  ja v  a 2s.c o  m*/
    int y = 0;
    JScrollPane scrollPane = getScrollPane();
    Insets scrollInsets = getScrollPaneInsets();

    if (scrollPane != null) {
        JInternalFrame allFrames[] = desktop.getAllFrames();
        for (int i = 0; i < allFrames.length; i++) {
            if (allFrames[i].getX() + allFrames[i].getWidth() > x) {
                x = allFrames[i].getX() + allFrames[i].getWidth();
            }
            if (allFrames[i].getY() + allFrames[i].getHeight() > y) {
                y = allFrames[i].getY() + allFrames[i].getHeight();
            }
        }
        Dimension d = scrollPane.getVisibleRect().getSize();
        if (scrollPane.getBorder() != null) {
            d.setSize(d.getWidth() - scrollInsets.left - scrollInsets.right,
                    d.getHeight() - scrollInsets.top - scrollInsets.bottom);
        }

        if (x <= d.getWidth())
            x = ((int) d.getWidth()) - 20;
        if (y <= d.getHeight())
            y = ((int) d.getHeight()) - 20;
        desktop.setAllSize(x, y);
        scrollPane.invalidate();
        scrollPane.validate();
    }
}

From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheet.java

protected void configureEnclosingScrollPane() {
    super.configureEnclosingScrollPane();
    Container p = getParent();/*from w w w. j  a  va 2s  .com*/
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this)
                return;

            configureScrollPaneHeaders(scrollPane);

            Border border = scrollPane.getBorder();
            if (border == null || border instanceof UIResource) {
                scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
            }
        }
    }
}

From source file:net.aepik.alasca.gui.ldap.SchemaObjectEditorFrame.java

/**
 * Build frame./*from w  w  w.j  a  v a 2 s. c om*/
 */
private void build() {
    setTitle("Proprits de l'objet " + objetSchema.getId());
    setSize(700, 400);
    setResizable(false);
    setLocationRelativeTo(mainFrame);

    if (mainFrame != null)
        setIconImage(mainFrame.getIconImage());

    // - Panel bouton du bas -

    JPanel boutonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    boutonsPanel.add(boutonOk);
    boutonsPanel.add(boutonAnnuler);

    // - Description -

    JTextArea textAreaValues = new JTextArea("Vous pouvez apporter des modifications sur les paramtres"
            + " de cet objet d'identifiant " + objetSchema.getId() + ". Les"
            + " modifications apportes  des paramtres non-cochs ne" + " seront pas prises en compte.");
    textAreaValues.setEditable(false);
    textAreaValues.setLineWrap(true);
    textAreaValues.setWrapStyleWord(true);
    textAreaValues.setFont((new JLabel()).getFont());
    textAreaValues.setBorder(BorderFactory.createEmptyBorder(7, 8, 7, 8));
    textAreaValues.setBackground((new JLabel()).getBackground());

    // - La table des valeurs -
    // Correction : Tri alphabtique des valeurs

    Enumeration<String> k = values.keys();
    String[] keys = new String[values.size()];

    for (int i = 0; i < keys.length; i++)
        keys[i] = k.nextElement();
    Arrays.sort(keys);

    JPanel colonne1 = new JPanel(new GridLayout(keys.length, 1));
    JPanel colonne2 = new JPanel(new GridLayout(keys.length, 1));

    // Enumeration<JComponent> l = labels.elements();
    // Enumeration<JComponent> v = values.elements();
    // Enumeration<String> k = values.keys();
    // JPanel colonne1 = new JPanel( new GridLayout( values.size(), 1 ) );
    // JPanel colonne2 = new JPanel( new GridLayout( values.size(), 1 ) );

    for (int i = 0; keys != null && i < keys.length; i++) {

        // while( l.hasMoreElements() && v.hasMoreElements() && k.hasMoreElements() ) {

        String key = keys[i];
        JComponent label = labels.get(key);
        JComponent value = values.get(key);
        JCheckBox checkbox = valuesPresent.get(key);

        // String key = k.nextElement();
        // JComponent label = l.nextElement();
        // JComponent value = v.nextElement();
        // JCheckBox checkbox = valuesPresent.get( key );

        if (!value.isEnabled() && value instanceof JTextField) {

            //value.setEnabled( true );

            JButton b = new JButton("...");
            b.setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createMatteBorder(0, 5, 0, 0, Color.white), b.getBorder()));
            b.addActionListener(new SchemaValueEditorLauncher(b, (JTextField) value, objetSchema, key));

            JPanel tmp = new JPanel(new BorderLayout());
            tmp.add(value, BorderLayout.CENTER);
            tmp.add(b, BorderLayout.EAST);
            tmp.setOpaque(false);
            value = tmp;
        }

        JPanel panelTmp1 = new JPanel(new BorderLayout());
        panelTmp1.add(checkbox, BorderLayout.WEST);
        panelTmp1.add(label, BorderLayout.CENTER);
        panelTmp1.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 3));
        colonne1.add(panelTmp1);

        JPanel panelTmp2 = new JPanel(new BorderLayout());
        panelTmp2.add(value, BorderLayout.CENTER);
        panelTmp2.setBorder(BorderFactory.createEmptyBorder(2, 3, 2, 3));
        colonne2.add(panelTmp2);

        checkbox.setOpaque(false);
        label.setOpaque(false);
        value.setOpaque(false);
        panelTmp1.setOpaque(false);
        panelTmp2.setOpaque(false);
    }

    JPanel tablePanel = new JPanel(new BorderLayout());
    tablePanel.add(colonne1, BorderLayout.WEST);
    tablePanel.add(colonne2, BorderLayout.EAST);
    tablePanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    colonne1.setOpaque(false);
    colonne2.setOpaque(false);
    tablePanel.setOpaque(false);

    JPanel tablePanelContainer = new JPanel(new BorderLayout());
    tablePanelContainer.add(tablePanel, BorderLayout.NORTH);
    tablePanelContainer.setBackground(Color.white);

    JList tmpForBorderList = new JList();
    JScrollPane tmpForBorderScroller = new JScrollPane(tmpForBorderList);

    JScrollPane tableScroller = new JScrollPane(tablePanelContainer);
    //tableScroller.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
    tableScroller.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 6, 1, 6),
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(" Listes des paramtres "),
                    BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5),
                            tmpForBorderScroller.getBorder()))));

    // - Organisation gnrale -

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(textAreaValues, BorderLayout.NORTH);
    mainPanel.add(tableScroller, BorderLayout.CENTER);

    JPanel mainPanelContainer = new JPanel(new BorderLayout());
    mainPanelContainer.add(mainPanel, BorderLayout.CENTER);
    mainPanelContainer.add(boutonsPanel, BorderLayout.SOUTH);
    mainPanelContainer.setBorder(BorderFactory.createEmptyBorder(2, 1, 1, 1));

    getContentPane().add(mainPanelContainer);

    // - Listeners -

    addWindowListener(this);
    boutonOk.addActionListener(this);
    boutonAnnuler.addActionListener(this);
}

From source file:edu.ku.brc.af.ui.forms.ViewFactory.java

/**
 * Creates a JTextArea for display purposes only.
 * @param cellField FormCellField info/* w  ww .j  a  v  a2 s.  c o m*/
 * @return the control
 */
public static JScrollPane changeTextAreaForDisplay(final JTextArea ta) {
    Insets insets = ta.getBorder().getBorderInsets(ta);
    ta.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.bottom));
    ta.setForeground(Color.BLACK);
    ta.setEditable(false);
    ta.setBackground(viewFieldColor.getColor());
    ta.setLineWrap(true);
    ta.setWrapStyleWord(true);

    JScrollPane scrollPane = new JScrollPane(ta);
    insets = scrollPane.getBorder().getBorderInsets(scrollPane);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane
            .setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.bottom));

    return scrollPane;
}