Example usage for javax.swing JPanel setBorder

List of usage examples for javax.swing JPanel setBorder

Introduction

In this page you can find the example usage for javax.swing JPanel 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:Main.java

/**
 * Adds a one pixel border of random color to this and all panels contained in this panel's
 * child hierarchy./*  w  ww  .j a va  2 s  .  c om*/
 */
public static void addDebugBorders(JPanel panel) {
    Color bcolor = new Color(_rando.nextInt(256), _rando.nextInt(256), _rando.nextInt(256));
    panel.setBorder(BorderFactory.createLineBorder(bcolor));

    for (int ii = 0; ii < panel.getComponentCount(); ii++) {
        Object child = panel.getComponent(ii);
        if (child instanceof JPanel) {
            addDebugBorders((JPanel) child);
        }
    }
}

From source file:Main.java

/**
 * Sets up the given window content pane by setting its border to provide a
 * good default spacer, and setting the content pane to the given components.
 * //from   ww w. ja  va2s.c o  m
 * @param aWindow
 *          the window to setup, cannot be <code>null</code>;
 * @param aCenterComponent
 *          the component that should appear at the center of the dialog;
 * @param aButtonPane
 *          the component that should appear at the bottom of the dialog
 * @param defaultButton
 *          the default button for this dialog; can be null for "none".
 * @see javax.swing.JRootPane#setDefaultButton(javax.swing.JButton)
 */
public static void setupWindowContentPane(final Window aWindow, final Component aCenterComponent,
        final Component aButtonPane, final JButton defaultButton) {
    final JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setBorder(BorderFactory.createEmptyBorder(DIALOG_PADDING, DIALOG_PADDING, //
            DIALOG_PADDING, DIALOG_PADDING));

    contentPane.add(aCenterComponent, BorderLayout.CENTER);
    contentPane.add(aButtonPane, BorderLayout.PAGE_END);

    if (aWindow instanceof JDialog) {
        ((JDialog) aWindow).setContentPane(contentPane);
        ((JDialog) aWindow).getRootPane().setDefaultButton(defaultButton);
    } else if (aWindow instanceof JFrame) {
        ((JFrame) aWindow).setContentPane(contentPane);
        ((JFrame) aWindow).getRootPane().setDefaultButton(defaultButton);
    }
    aWindow.pack();
}

From source file:Main.java

public static JPanel createTextComponentPane(String labelText, JTextComponent textComp, Font font,
        Color bgColor, boolean isVertical) {
    JPanel outPane = new JPanel();
    outPane.setLayout(new BorderLayout());
    outPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    JLabel labelOut = new JLabel(labelText, SwingConstants.LEFT);
    if (isVertical) {
        outPane.add(labelOut, BorderLayout.NORTH);
    } else {/*from   w  w w  .j  av a  2  s.  co  m*/
        outPane.add(labelOut, BorderLayout.WEST);
    }
    if (textComp instanceof JTextArea) {
        outPane.add(createScrollPane((JTextArea) textComp, font, bgColor), BorderLayout.CENTER);
    } else {
        textComp.setBackground(bgColor);
        textComp.setFont(font);
        outPane.add(textComp, BorderLayout.CENTER);
    }
    return outPane;
}

From source file:RadioButtonUtils.java

public static Container createRadioButtonGrouping(String elements[], String title) {
    JPanel panel = new JPanel(new GridLayout(0, 1));

    if (title != null) {
        Border border = BorderFactory.createTitledBorder(title);
        panel.setBorder(border);
    }/* w w  w .j av  a2  s  . c o m*/

    ButtonGroup group = new ButtonGroup();
    JRadioButton aRadioButton;

    for (int i = 0, n = elements.length; i < n; i++) {
        aRadioButton = new JRadioButton(elements[i]);
        panel.add(aRadioButton);
        group.add(aRadioButton);
    }
    return panel;
}

From source file:Main.java

public static boolean showModalDialogOnEDT(JComponent contents, String title, String okButtonMessage,
        String cancelButtonMessage, ModalityType modalityType, final boolean systemExitOnDisposed) {

    class Result {
        boolean OK = false;
    }/*from  w  w w .  jav  a 2 s. c o m*/
    final Result result = new Result();

    final JDialog dialog = new JDialog((Frame) null, title, true) {
        @Override
        public void dispose() {
            super.dispose();
            if (systemExitOnDisposed) {
                System.exit(0);
            }
        }
    };

    // ensure it doesn't block other dialogs
    if (modalityType != null) {
        dialog.setModalityType(modalityType);
    }

    // See http://stackoverflow.com/questions/1343542/how-do-i-close-a-jdialog-and-have-the-window-event-listeners-be-notified
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
    if (okButtonMessage != null) {
        buttonPane.add(new JButton(new AbstractAction(okButtonMessage) {

            @Override
            public void actionPerformed(ActionEvent e) {
                result.OK = true;
                dialog.dispose();
            }
        }));
    }

    if (cancelButtonMessage != null) {
        buttonPane.add(new JButton(new AbstractAction(cancelButtonMessage) {

            @Override
            public void actionPerformed(ActionEvent e) {
                dialog.dispose();
            }
        }));
    }

    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BorderLayout());
    panel.add(contents, BorderLayout.CENTER);
    panel.add(buttonPane, BorderLayout.SOUTH);

    // startup frame
    dialog.getContentPane().add(panel);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.pack();

    // This hopefully centres the dialog even though the parameter is null 
    // see http://stackoverflow.com/questions/213266/how-do-i-center-a-jdialog-on-screen
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);

    return result.OK;
}

From source file:Main.java

/**
 * Puts an array of components into a new panel with a label.
 * /*from  ww  w. ja va  2 s . c  o m*/
 * @param a
 *            The Components to add.
 * @param label
 *            The label of the panel.
 * @return A Panel with the given label and the components inside.
 */
public static JPanel addToLabeledPanel(Component[] a, String label) {
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, a.length));
    addAll(a, panel);
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), label));
    return panel;
}

From source file:Main.java

/**
 * Creates a labeled panel containing a slider and considering
 * a particular width//from w  ww  .  j a  v  a2 s  .c o m
 * 
 * @param slider
 * @param label
 * @return a panel for the slider
 */
public static JPanel createSliderPanel(final JSlider slider, String label, int width) {
    final JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.setBorder(new TitledBorder(label));
    p.setPreferredSize(new Dimension(width, 60));
    p.add(slider);
    return p;
}

From source file:eu.delving.sip.base.ReportChartHelper.java

public static JComponent createLinkChart(DataSet dataSet, String prefix,
        Map<RecDef.Check, LinkFile.LinkStats> linkStatsMap) {
    JPanel p = new JPanel(new GridLayout(0, 1));
    for (Map.Entry<RecDef.Check, LinkFile.LinkStats> entry : linkStatsMap.entrySet()) {
        JPanel pp = new JPanel(new GridLayout(1, 0));
        pp.setBorder(BorderFactory.createTitledBorder(entry.getKey().toString()));
        for (Map.Entry<String, PieDataset> datasetEntry : entry.getValue().createPies().entrySet()) {
            JFreeChart chart = ChartFactory.createRingChart(datasetEntry.getKey(), datasetEntry.getValue(),
                    true, false, Locale.getDefault());
            RingPlot plot = (RingPlot) chart.getPlot();
            plot.setLabelGenerator(null);
            plot.setNoDataMessage("No data available");
            plot.setSectionDepth(0.34999999999999998D);
            plot.setCircular(true);/*from w  w  w  .  j  av a2s .c om*/
            plot.setLabelGap(0.02D);
            pp.add(new ChartPanel(chart));
        }
        p.add(pp);
    }
    return p;
}

From source file:de.tbuchloh.kiskis.gui.dialogs.ImportDialog.java

private static void addPadding(final JPanel panel) {
    panel.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25));
}

From source file:components.ListDialogRunner.java

public static JPanel createUI() {
    //Create the labels.
    JLabel intro = new JLabel("The chosen name:");
    final JLabel name = new JLabel(names[1]);
    intro.setLabelFor(name);//from w w  w.  j av  a2 s . c  om

    //Use a wacky font if it exists. If not, this falls
    //back to a font we know exists.
    name.setFont(getAFont());

    //Create the button.
    final JButton button = new JButton("Pick a new name...");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String selectedName = ListDialog.showDialog(frame, button, "Baby names ending in O:",
                    "Name Chooser", names, name.getText(), "Cosmo  ");
            name.setText(selectedName);
        }
    });

    //Create the panel we'll return and set up the layout.
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20));
    intro.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    name.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    button.setAlignmentX(JComponent.CENTER_ALIGNMENT);

    //Add the labels to the content pane.
    panel.add(intro);
    panel.add(Box.createVerticalStrut(5)); //extra space
    panel.add(name);

    //Add a vertical spacer that also guarantees us a minimum width:
    panel.add(Box.createRigidArea(new Dimension(150, 10)));

    //Add the button.
    panel.add(button);

    return panel;
}