Example usage for javax.swing BorderFactory createCompoundBorder

List of usage examples for javax.swing BorderFactory createCompoundBorder

Introduction

In this page you can find the example usage for javax.swing BorderFactory createCompoundBorder.

Prototype

public static CompoundBorder createCompoundBorder(Border outsideBorder, Border insideBorder) 

Source Link

Document

Creates a compound border specifying the border objects to use for the outside and inside edges.

Usage

From source file:api3.transform.PlotWave.java

public void plot(double[][] signal, String name, long samplerate) {

    frame.setTitle(name);/* ww  w .  j  a  v  a2 s .  co m*/

    XYSeries[] soundWave = new XYSeries[signal.length];
    for (int j = 0; j < signal.length; ++j) {
        soundWave[j] = new XYSeries("sygnal" + j);
        for (int i = 0; i < signal[0].length; ++i) {
            double index = (samplerate == 0) ? i : 1000.0 * (double) i / (double) samplerate;
            soundWave[j].add(index, signal[j][i]);
        }
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    for (int j = 0; j < signal.length; ++j) {
        dataset.addSeries(soundWave[j]);
    }

    JFreeChart chart = //            (samplerate ==0 )?
            //            ChartFactory.createXYBarChart(
            //            name,
            //            "prbka",
            //            false,
            //            "warto",
            //            new XYBarDataset(dataset,0.0625),
            //            PlotOrientation.VERTICAL,
            //            true,false,false)
            //            :
            ChartFactory.createXYLineChart(name, "prbka", "warto", dataset,
                    PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();

    slider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            int value = slider.getValue();
            double minimum = domainAxis.getRange().getLowerBound();
            double maximum = domainAxis.getRange().getUpperBound();
            double delta = (0.1f * (domainAxis.getRange().getLength()));
            if (value < lastValue) { // left
                minimum = minimum - delta;
                maximum = maximum - delta;
            } else { // right
                minimum = minimum + delta;
                maximum = maximum + delta;
            }
            DateRange range = new DateRange(minimum, maximum);
            domainAxis.setRange(range);
            lastValue = value;
            if (lastValue == slider.getMinimum() || lastValue == slider.getMaximum()) {
                slider.setValue(SLIDER_DEFAULT_VALUE);
            }
        }

    });

    plot.addRangeMarker(new ValueMarker(0, Color.BLACK, new BasicStroke(1)));

    ChartPanel chartPanel = new ChartPanel(chart);
    Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createEtchedBorder());
    chartPanel.setBorder(border);

    chartPanel.addMouseWheelListener(addZoomWheel());

    panel.add(chartPanel);
    JPanel dashboard = new JPanel(new BorderLayout());
    dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
    dashboard.add(slider);
    panel.add(dashboard, BorderLayout.SOUTH);

    frame.getContentPane().add((JPanel) panel, BorderLayout.CENTER);

    frame.pack();
    frame.setVisible(true);
}

From source file:com.xilinx.kintex7.ThermoPlot.java

public ChartPanel getChart() {
    ChartPanel chartpanel = new ChartPanel(chart);
    chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""),
            BorderFactory.createRaisedBevelBorder()));
    return chartpanel;
}

From source file:SimpleDateFormatDemo.java

public SimpleDateFormatDemo() {

    today = new Date();
    availableLocales = new LocaleGroup();

    String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z",
            "EEE, MMM d, ''yy", "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" };

    currentPattern = patternExamples[0];

    // Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Enter the pattern string or");
    JLabel patternLabel2 = new JLabel("select one from the list:");
    patternLabel1.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternLabel2.setAlignmentX(Component.LEFT_ALIGNMENT);

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setSelectedIndex(0);/*  w w w . j  ava2s .  c  o m*/
    patternList.setEditable(true);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    PatternListener patternListener = new PatternListener();
    patternList.addActionListener(patternListener);

    // Set up the UI for selecting a locale.
    JLabel localeLabel = new JLabel("Select a Locale from the list:");
    localeLabel.setAlignmentX(Component.LEFT_ALIGNMENT);

    JComboBox localeList = new JComboBox(availableLocales.getStrings());
    localeList.setSelectedIndex(0);
    localeList.setAlignmentX(Component.LEFT_ALIGNMENT);
    LocaleListener localeListener = new LocaleListener();
    localeList.addActionListener(localeListener);

    // Create the UI for displaying result
    JLabel resultLabel = new JLabel("Current Date and Time", JLabel.LEFT);
    resultLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setAlignmentX(Component.LEFT_ALIGNMENT);
    result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Lay out everything
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.Y_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternPanel.add(patternList);

    JPanel localePanel = new JPanel();
    localePanel.setLayout(new BoxLayout(localePanel, BoxLayout.Y_AXIS));
    localePanel.add(localeLabel);
    localePanel.add(localeList);

    JPanel resultPanel = new JPanel();
    resultPanel.setLayout(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    patternPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    localePanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    resultPanel.setAlignmentX(Component.CENTER_ALIGNMENT);

    add(patternPanel);
    add(Box.createVerticalStrut(10));
    add(localePanel);
    add(Box.createVerticalStrut(10));
    add(resultPanel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    reformat();

}

From source file:DiningPhilosophers.java

public void init() {

    imgs[HUNGRYDUKE] = new ImageIcon(getURL("images/hungryduke.gif"));
    imgs[RIGHTSPOONDUKE] = new ImageIcon(getURL("images/rightspoonduke.gif"));
    imgs[BOTHSPOONSDUKE] = new ImageIcon(getURL("images/bothspoonsduke.gif"));

    width = imgs[HUNGRYDUKE].getIconWidth() + (int) (MARGIN * 2.0);
    height = imgs[HUNGRYDUKE].getIconHeight() + (int) (MARGIN * 2.0);
    spacing = width + MARGIN;/*  w  w w.  ja  va  2 s. c om*/

    GridBagLayout gridBag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    JPanel contentPane = new JPanel();
    contentPane.setLayout(gridBag);

    philosopherArea = new JPanel(null);
    philosopherArea.setBackground(Color.white);
    Dimension preferredSize = createPhilosophersAndChopsticks();
    philosopherArea.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    philosopherArea.setPreferredSize(preferredSize);

    c.fill = GridBagConstraints.BOTH;
    c.weighty = 1.0;
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    gridBag.setConstraints(philosopherArea, c);
    contentPane.add(philosopherArea);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    c.weighty = 0.0;
    gridBag.setConstraints(stopStartButton, c);
    contentPane.add(stopStartButton);

    c.gridwidth = GridBagConstraints.RELATIVE; //don't end row
    c.weightx = 1.0;
    c.weighty = 0.0;
    gridBag.setConstraints(grabDelaySlider, c);
    contentPane.add(grabDelaySlider);

    c.weightx = 0.0;
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    gridBag.setConstraints(label, c);
    contentPane.add(label);
    contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);

    stopStartButton.addActionListener(this);
    grabDelaySlider.addChangeListener(this);

}

From source file:MultiListener.java

public MultiListener() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    JLabel l = null;//w  w  w.  ja va 2  s . c o m

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    l = new JLabel("What MultiListener hears:");
    gridbag.setConstraints(l, c);
    add(l);

    c.weighty = 1.0;
    topTextArea = new JTextArea();
    topTextArea.setEditable(false);
    JScrollPane topScrollPane = new JScrollPane(topTextArea);
    Dimension preferredSize = new Dimension(200, 75);
    topScrollPane.setPreferredSize(preferredSize);
    gridbag.setConstraints(topScrollPane, c);
    add(topScrollPane);

    c.weightx = 0.0;
    c.weighty = 0.0;
    l = new JLabel("What Eavesdropper hears:");
    gridbag.setConstraints(l, c);
    add(l);

    c.weighty = 1.0;
    bottomTextArea = new JTextArea();
    bottomTextArea.setEditable(false);
    JScrollPane bottomScrollPane = new JScrollPane(bottomTextArea);
    bottomScrollPane.setPreferredSize(preferredSize);
    gridbag.setConstraints(bottomScrollPane, c);
    add(bottomScrollPane);

    c.weightx = 1.0;
    c.weighty = 0.0;
    c.gridwidth = 1;
    c.insets = new Insets(10, 10, 0, 10);
    button1 = new JButton("Blah blah blah");
    gridbag.setConstraints(button1, c);
    add(button1);

    c.gridwidth = GridBagConstraints.REMAINDER;
    button2 = new JButton("You don't say!");
    gridbag.setConstraints(button2, c);
    add(button2);

    button1.addActionListener(this);
    button2.addActionListener(this);

    button2.addActionListener(new Eavesdropper(bottomTextArea));

    setPreferredSize(new Dimension(450, 450));
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 1, 2, 2, Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
}

From source file:IconDemoApplet.java

public void init() {
    //Parse the applet parameters
    pictures = parseParameters();//ww  w .j a  v  a 2  s.  co m

    //If the applet tag doesn't provide an "IMAGE0" parameter,
    //display an error message.
    if (pictures.size() == 0) {
        captionLabel = new JLabel("No images listed in applet tag.");
        captionLabel.setHorizontalAlignment(JLabel.CENTER);
        getContentPane().add(captionLabel);
        return;
    }

    //NOW CREATE THE GUI COMPONENTS

    //A label to identify XX of XX.
    numberLabel = new JLabel("Picture " + (current + 1) + " of " + pictures.size());
    numberLabel.setHorizontalAlignment(JLabel.LEFT);
    numberLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 5));

    //A label for the caption.
    final Photo first = (Photo) pictures.firstElement();
    captionLabel = new JLabel(first.caption);
    captionLabel.setHorizontalAlignment(JLabel.CENTER);
    captionLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));

    //A label for displaying the photographs.
    photographLabel = new JLabel("Loading first image...");
    photographLabel.setHorizontalAlignment(JLabel.CENTER);
    photographLabel.setVerticalAlignment(JLabel.CENTER);
    photographLabel.setVerticalTextPosition(JLabel.CENTER);
    photographLabel.setHorizontalTextPosition(JLabel.CENTER);
    photographLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    photographLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0),
            photographLabel.getBorder()));

    //Set the preferred size for the picture,
    //with room for the borders.
    Insets i = photographLabel.getInsets();
    photographLabel.setPreferredSize(
            new Dimension(widthOfWidest + i.left + i.right, heightOfTallest + i.bottom + i.top));

    //Create the next and previous buttons.
    ImageIcon nextIcon = new ImageIcon(getURL(imagedir + "right.gif"));
    ImageIcon dimmedNextIcon = new ImageIcon(getURL(imagedir + "dimmedRight.gif"));
    ImageIcon previousIcon = new ImageIcon(getURL(imagedir + "left.gif"));
    ImageIcon dimmedPreviousIcon = new ImageIcon(getURL(imagedir + "dimmedLeft.gif"));

    previousButton = new JButton("Previous Picture", previousIcon);
    previousButton.setDisabledIcon(dimmedPreviousIcon);
    previousButton.setVerticalTextPosition(AbstractButton.CENTER);
    previousButton.setHorizontalTextPosition(AbstractButton.RIGHT);
    previousButton.setMnemonic(KeyEvent.VK_P);
    previousButton.setActionCommand("previous");
    previousButton.addActionListener(this);
    previousButton.setEnabled(false);

    nextButton = new JButton("Next Picture", nextIcon);
    nextButton.setDisabledIcon(dimmedNextIcon);
    nextButton.setVerticalTextPosition(AbstractButton.CENTER);
    nextButton.setHorizontalTextPosition(AbstractButton.LEFT);
    nextButton.setMnemonic(KeyEvent.VK_N);
    nextButton.setActionCommand("next");
    nextButton.addActionListener(this);

    //Lay out the GUI.
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    Container contentPane = getContentPane();
    contentPane.setLayout(layout);

    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    layout.setConstraints(numberLabel, c);
    contentPane.add(numberLabel);

    layout.setConstraints(captionLabel, c);
    contentPane.add(captionLabel);

    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.BOTH;
    layout.setConstraints(photographLabel, c);
    contentPane.add(photographLabel);

    c.gridwidth = GridBagConstraints.RELATIVE;
    c.fill = GridBagConstraints.HORIZONTAL;
    layout.setConstraints(previousButton, c);
    contentPane.add(previousButton);

    c.gridwidth = GridBagConstraints.REMAINDER;
    layout.setConstraints(nextButton, c);
    contentPane.add(nextButton);

    //Start loading the image for the first photograph now.
    //The loadImage method uses a SwingWorker
    //to load the image in a separate thread.
    loadImage(imagedir + first.filename, current);
}

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  w  w w . j a  va  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:org.jdal.swing.form.FormUtils.java

/**
 * Create Titled Border// w  w  w  . j  a  v a 2 s  . co  m
 * @param name the title
 * @return Border
 */
public static Border createTitledBorder(String name) {
    Border margin = BorderFactory.createEmptyBorder(10, 10, 10, 10);
    Border title = BorderFactory.createTitledBorder(name);

    return BorderFactory.createCompoundBorder(title, margin);
}

From source file:com.xilinx.kintex7.DMABarChart.java

public ChartPanel getChart(String title) {
    ChartPanel chartpanel = new ChartPanel(chart);
    chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(title),
            BorderFactory.createRaisedBevelBorder()));
    return chartpanel;
}

From source file:be.ac.ua.comp.scarletnebula.gui.addserverwizard.ChooseImagePage.java

private final JPanel getAllImagesPanel(final CloudProvider provider) {
    final JPanel panel = new JPanel(new BorderLayout());
    final TableRowSorter<MachineImageTableModel> sorter = new TableRowSorter<MachineImageTableModel>(
            allImagesModel);//from  w ww . j  a va 2  s.  co m
    allImagesTable.setRowSorter(sorter);
    allImagesTable.setFillsViewportHeight(true);
    allImagesTable.addMouseListener(new SmartImageModelContextMenuMouseListener(provider, allImagesModel,
            allImagesTable, favoriteImagesPanel.getModel()));

    final JPanel aboveTable = new JPanel(new BorderLayout());
    final JPanel searchPanel = getSearchPanel(sorter);

    aboveTable.add(searchPanel, BorderLayout.NORTH);
    aboveTable.add(throbberPanel, BorderLayout.SOUTH);

    panel.add(aboveTable, BorderLayout.NORTH);

    final JScrollPane tableScrollPane = new JScrollPane(allImagesTable);
    tableScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 20, 10, 20),
            BorderFactory.createBevelBorder(BevelBorder.LOWERED)));

    panel.add(tableScrollPane, BorderLayout.CENTER);

    return panel;
}