Example usage for javax.swing BorderFactory createEmptyBorder

List of usage examples for javax.swing BorderFactory createEmptyBorder

Introduction

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

Prototype

public static Border createEmptyBorder(int top, int left, int bottom, int right) 

Source Link

Document

Creates an empty border that takes up space but which does no drawing, specifying the width of the top, left, bottom, and right sides.

Usage

From source file:BorderDemo.java

public BorderDemo() {
    super("BorderDemo");
    Border blackline, etched, raisedbevel, loweredbevel, empty;

    //A border that puts 10 extra pixels at the sides and
    //bottom of each pane.
    Border paneEdge = BorderFactory.createEmptyBorder(0, 10, 10, 10);

    blackline = BorderFactory.createLineBorder(Color.black);
    etched = BorderFactory.createEtchedBorder();
    raisedbevel = BorderFactory.createRaisedBevelBorder();
    loweredbevel = BorderFactory.createLoweredBevelBorder();
    empty = BorderFactory.createEmptyBorder();

    //First pane: simple borders
    JPanel simpleBorders = new JPanel();
    simpleBorders.setBorder(paneEdge);/*  w  w w .j  ava2s.  com*/
    simpleBorders.setLayout(new BoxLayout(simpleBorders, BoxLayout.Y_AXIS));

    addCompForBorder(blackline, "line border", simpleBorders);
    addCompForBorder(etched, "etched border", simpleBorders);
    addCompForBorder(raisedbevel, "raised bevel border", simpleBorders);
    addCompForBorder(loweredbevel, "lowered bevel border", simpleBorders);
    addCompForBorder(empty, "empty border", simpleBorders);

    //Second pane: matte borders
    JPanel matteBorders = new JPanel();
    matteBorders.setBorder(paneEdge);
    matteBorders.setLayout(new BoxLayout(matteBorders, BoxLayout.Y_AXIS));

    //XXX: We *should* size the component so that the
    //XXX: icons tile OK. Without that, the icons are
    //XXX: likely to be cut off and look bad.
    ImageIcon icon = new ImageIcon("images/left.gif"); //20x22
    Border border = BorderFactory.createMatteBorder(-1, -1, -1, -1, icon);
    addCompForBorder(border, "matte border (-1,-1,-1,-1,icon)", matteBorders);
    border = BorderFactory.createMatteBorder(1, 5, 1, 1, Color.red);
    addCompForBorder(border, "matte border (1,5,1,1,Color.red)", matteBorders);
    border = BorderFactory.createMatteBorder(0, 20, 0, 0, icon);
    addCompForBorder(border, "matte border (0,20,0,0,icon)", matteBorders);

    //Third pane: titled borders
    JPanel titledBorders = new JPanel();
    titledBorders.setBorder(paneEdge);
    titledBorders.setLayout(new BoxLayout(titledBorders, BoxLayout.Y_AXIS));
    TitledBorder titled;

    titled = BorderFactory.createTitledBorder("title");
    addCompForBorder(titled, "default titled border" + " (default just., default pos.)", titledBorders);

    titled = BorderFactory.createTitledBorder(blackline, "title");
    addCompForTitledBorder(titled, "titled line border" + " (centered, default pos.)", TitledBorder.CENTER,
            TitledBorder.DEFAULT_POSITION, titledBorders);

    titled = BorderFactory.createTitledBorder(etched, "title");
    addCompForTitledBorder(titled, "titled etched border" + " (right just., default pos.)", TitledBorder.RIGHT,
            TitledBorder.DEFAULT_POSITION, titledBorders);

    titled = BorderFactory.createTitledBorder(loweredbevel, "title");
    addCompForTitledBorder(titled, "titled lowered bevel border" + " (default just., above top)",
            TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.ABOVE_TOP, titledBorders);

    titled = BorderFactory.createTitledBorder(empty, "title");
    addCompForTitledBorder(titled, "titled empty border" + " (default just., bottom)",
            TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.BOTTOM, titledBorders);

    //Fourth pane: compound borders
    JPanel compoundBorders = new JPanel();
    compoundBorders.setBorder(paneEdge);
    compoundBorders.setLayout(new BoxLayout(compoundBorders, BoxLayout.Y_AXIS));
    Border redline = BorderFactory.createLineBorder(Color.red);

    Border compound;
    compound = BorderFactory.createCompoundBorder(raisedbevel, loweredbevel);
    addCompForBorder(compound, "compound border (two bevels)", compoundBorders);

    compound = BorderFactory.createCompoundBorder(redline, compound);
    addCompForBorder(compound, "compound border (add a red outline)", compoundBorders);

    titled = BorderFactory.createTitledBorder(compound, "title", TitledBorder.CENTER,
            TitledBorder.BELOW_BOTTOM);
    addCompForBorder(titled, "titled compound border" + " (centered, below bottom)", compoundBorders);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Simple", null, simpleBorders, null);
    tabbedPane.addTab("Matte", null, matteBorders, null);
    tabbedPane.addTab("Titled", null, titledBorders, null);
    tabbedPane.addTab("Compound", null, compoundBorders, null);
    tabbedPane.setSelectedIndex(0);

    getContentPane().add(tabbedPane, BorderLayout.CENTER);
}

From source file:ProgressDialog.java

private void setupComponent() {

    JPanel contentPane = (JPanel) getContentPane();
    contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new GridBagLayout());
    GridBagConstraints gc = new GridBagConstraints();
    gc.gridx = 0;/*from w  ww  . j  a  va2  s  . c  om*/
    gc.gridy = GridBagConstraints.RELATIVE;
    gc.anchor = GridBagConstraints.NORTHWEST;
    contentPane.add(lblMessage, gc);
    gc.weightx = 1;
    gc.fill = GridBagConstraints.HORIZONTAL;
    contentPane.add(progressBar, gc);

    setTitle("");
    setModal(true);
    pack();

}

From source file:com.tencent.wstt.apt.chart.AbstractRealTimeLineChart.java

/**
 * ?jfreechatpanel/*  w w  w . ja v  a2 s . c o m*/
 */
public AbstractRealTimeLineChart() {
    super(new BorderLayout());
    chart = createChart();
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    this.add(chartPanel);
}

From source file:events.FocusEventDemo.java

public void addComponentsToPane(final Container pane) {
    GridBagLayout gridbag = new GridBagLayout();
    pane.setLayout(gridbag);/*from  w ww  .java 2s.  co m*/

    GridBagConstraints c = new GridBagConstraints();

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0; //Make column as wide as possible.
    JTextField textField = new JTextField("A TextField");
    textField.setMargin(new Insets(0, 2, 0, 2));
    textField.addFocusListener(this);
    gridbag.setConstraints(textField, c);
    add(textField);

    c.weightx = 0.1; //Widen every other column a bit, when possible.
    c.fill = GridBagConstraints.NONE;
    JLabel label = new JLabel("A Label");
    label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    label.addFocusListener(this);
    gridbag.setConstraints(label, c);
    add(label);

    String comboPrefix = "ComboBox Item #";
    final int numItems = 15;
    Vector<String> vector = new Vector<String>(numItems);
    for (int i = 0; i < numItems; i++) {
        vector.addElement(comboPrefix + i);
    }
    JComboBox comboBox = new JComboBox(vector);
    comboBox.addFocusListener(this);
    gridbag.setConstraints(comboBox, c);
    add(comboBox);

    c.gridwidth = GridBagConstraints.REMAINDER;
    JButton button = new JButton("A Button");
    button.addFocusListener(this);
    gridbag.setConstraints(button, c);
    add(button);

    c.weightx = 0.0;
    c.weighty = 0.1;
    c.fill = GridBagConstraints.BOTH;
    String listPrefix = "List Item #";
    Vector<String> listVector = new Vector<String>(numItems);
    for (int i = 0; i < numItems; i++) {
        listVector.addElement(listPrefix + i);
    }
    JList list = new JList(listVector);
    list.setSelectedIndex(1); //It's easier to see the focus change
    //if an item is selected.
    list.addFocusListener(this);
    JScrollPane listScrollPane = new JScrollPane(list);

    gridbag.setConstraints(listScrollPane, c);
    add(listScrollPane);

    c.weighty = 1.0; //Make this row as tall as possible.
    c.gridheight = GridBagConstraints.REMAINDER;
    //Set up the area that reports focus-gained and focus-lost events.
    display = new JTextArea();
    display.setEditable(false);
    //The setRequestFocusEnabled method prevents a
    //component from being clickable, but it can still
    //get the focus through the keyboard - this ensures
    //user accessibility.
    display.setRequestFocusEnabled(false);
    display.addFocusListener(this);
    JScrollPane displayScrollPane = new JScrollPane(display);

    gridbag.setConstraints(displayScrollPane, c);
    add(displayScrollPane);
    setPreferredSize(new Dimension(450, 450));
    ((JPanel) pane).setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:com.adito.upgrade.GUIUpgrader.java

public GUIUpgrader() {
    super(new BorderLayout());
    JPanel info = new JPanel(new BorderLayout(2, 2));

    //        info.setBackground(Color.white);
    //        info.setForeground(Color.black);
    //        info.setOpaque(true);
    info.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    JLabel l = new JLabel("<html><p>This utility upgrades configuration from "
            + "one version 0.1.16 installation to another "
            + "0.2.5+ installation. You may choose which resources you "
            + "wish to be copied. If resources with the same name already " + "exist they will be left as is.");
    l.setIcon(new ImageIcon(GUIUpgrader.class.getResource("upgrader-48x48.png")));
    info.add(l, BorderLayout.CENTER);
    info.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH);
    mainPanel = new JPanel(new BorderLayout());
    add(info, BorderLayout.NORTH);
    add(mainPanel, BorderLayout.CENTER);

    // Installations panel
    JPanel installations = new JPanel(new GridBagLayout());
    installations.setBorder(BorderFactory.createTitledBorder("Installations"));
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(2, 2, 2, 2);
    gbc.weightx = 2.0;/*from  w  ww  .jav a2  s  .c om*/
    UIUtil.jGridBagAdd(installations, new JLabel("Source"), gbc, GridBagConstraints.REMAINDER);
    gbc.weightx = 1.0;
    source = new JTextField();
    source.getDocument().addDocumentListener(this);
    UIUtil.jGridBagAdd(installations, source, gbc, GridBagConstraints.RELATIVE);
    browseSource = new JButton("Browse");
    browseSource.setMnemonic('b');
    browseSource.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(source.getText());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setDialogTitle("Select source installation directory (0.16.1)");
            if (chooser.showOpenDialog(GUIUpgrader.this) == JFileChooser.APPROVE_OPTION) {
                source.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    gbc.weightx = 0.0;
    UIUtil.jGridBagAdd(installations, browseSource, gbc, GridBagConstraints.REMAINDER);
    gbc.weightx = 2.0;
    UIUtil.jGridBagAdd(installations, new JLabel("Target"), gbc, GridBagConstraints.REMAINDER);
    gbc.weightx = 1.0;
    target = new JTextField(System.getProperty("user.dir"));
    target.getDocument().addDocumentListener(this);
    UIUtil.jGridBagAdd(installations, target, gbc, GridBagConstraints.RELATIVE);
    browseTarget = new JButton("Browse");
    browseTarget.setMnemonic('r');
    browseTarget.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(target.getText());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setDialogTitle("Select target installation directory (0.2.5+)");
            if (chooser.showOpenDialog(GUIUpgrader.this) == JFileChooser.APPROVE_OPTION) {
                target.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    gbc.weightx = 0.0;
    UIUtil.jGridBagAdd(installations, browseTarget, gbc, GridBagConstraints.REMAINDER);
    mainPanel.add(installations, BorderLayout.NORTH);

    // Upgrade selection
    upgradeSelectionPanel = new JPanel();
    upgradeSelectionPanel.setBorder(BorderFactory.createTitledBorder("Upgrades"));
    upgradeSelectionPanel.setLayout(new BoxLayout(upgradeSelectionPanel, BoxLayout.Y_AXIS));
    mainPanel.add(upgradeSelectionPanel, BorderLayout.CENTER);

}

From source file:com.game.ui.views.ItemPanel.java

public void doGui() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel noteLbl = new JLabel(
            "<html><div style='width : 500px;'>Pls select a value from the dropdown or you can create a new "
                    + "entity below. Once selected an Item, its' details will be available below</div></html>");
    noteLbl.setAlignmentX(0);//from ww w . j a va 2 s. c o  m
    add(noteLbl);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    if (ringPanel) {
        for (Item item : GameBean.ringDetails) {
            model.addElement(((Ring) item).getName());
        }
    } else if (armourPanel) {
        for (Item item : GameBean.armourDetails) {
            model.addElement(((Armour) item).getName());
        }
    } else if (potionPanel) {
        for (Item item : GameBean.potionDetails) {
            model.addElement(((Potion) item).getName());
        }
    } else if (treasurePanel) {
        for (Item item : GameBean.treasureDetails) {
            model.addElement(((Treasure) item).getName());
        }
    }
    doCommonStuffForDropDown(model);
    doCommonStuffForContent();
}

From source file:components.ButtonTabComponent.java

public ButtonTabComponent(final JTabbedPane pane) {
    //unset default FlowLayout' gaps
    super(new FlowLayout(FlowLayout.LEFT, 0, 0));
    if (pane == null) {
        throw new NullPointerException("TabbedPane is null");
    }/*from   ww w .j  a  va 2  s . c  o m*/
    this.pane = pane;
    setOpaque(false);

    //make JLabel read titles from JTabbedPane
    JLabel label = new JLabel() {
        public String getText() {
            int i = pane.indexOfTabComponent(ButtonTabComponent.this);
            if (i != -1) {
                return pane.getTitleAt(i);
            }
            return null;
        }
    };

    add(label);
    //add more space between the label and the button
    label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
    //tab button
    JButton button = new TabButton();
    add(button);
    //add more space to the top of the component
    setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
}

From source file:components.ConversionPanel.java

ConversionPanel(Converter myController, String myTitle, Unit[] myUnits, ConverterRangeModel myModel) {
    if (MULTICOLORED) {
        setOpaque(true);/*from w ww.j ava2 s.co m*/
        setBackground(new Color(0, 255, 255));
    }
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(myTitle),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Save arguments in instance variables.
    controller = myController;
    units = myUnits;
    title = myTitle;
    sliderModel = myModel;

    //Create the text field format, and then the text field.
    numberFormat = NumberFormat.getNumberInstance();
    numberFormat.setMaximumFractionDigits(2);
    NumberFormatter formatter = new NumberFormatter(numberFormat);
    formatter.setAllowsInvalid(false);
    formatter.setCommitsOnValidEdit(true);//seems to be a no-op --
    //aha -- it changes the value property but doesn't cause the result to
    //be parsed (that happens on focus loss/return, I think).
    //
    textField = new JFormattedTextField(formatter);
    textField.setColumns(10);
    textField.setValue(new Double(sliderModel.getDoubleValue()));
    textField.addPropertyChangeListener(this);

    //Add the combo box.
    unitChooser = new JComboBox();
    for (int i = 0; i < units.length; i++) { //Populate it.
        unitChooser.addItem(units[i].description);
    }
    unitChooser.setSelectedIndex(0);
    sliderModel.setMultiplier(units[0].multiplier);
    unitChooser.addActionListener(this);

    //Add the slider.
    slider = new JSlider(sliderModel);
    sliderModel.addChangeListener(this);

    //Make the text field/slider group a fixed size
    //to make stacked ConversionPanels nicely aligned.
    JPanel unitGroup = new JPanel() {
        public Dimension getMinimumSize() {
            return getPreferredSize();
        }

        public Dimension getPreferredSize() {
            return new Dimension(150, super.getPreferredSize().height);
        }

        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
    };
    unitGroup.setLayout(new BoxLayout(unitGroup, BoxLayout.PAGE_AXIS));
    if (MULTICOLORED) {
        unitGroup.setOpaque(true);
        unitGroup.setBackground(new Color(0, 0, 255));
    }
    unitGroup.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
    unitGroup.add(textField);
    unitGroup.add(slider);

    //Create a subpanel so the combo box isn't too tall
    //and is sufficiently wide.
    JPanel chooserPanel = new JPanel();
    chooserPanel.setLayout(new BoxLayout(chooserPanel, BoxLayout.PAGE_AXIS));
    if (MULTICOLORED) {
        chooserPanel.setOpaque(true);
        chooserPanel.setBackground(new Color(255, 0, 255));
    }
    chooserPanel.add(unitChooser);
    chooserPanel.add(Box.createHorizontalStrut(100));

    //Put everything together.
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
    add(unitGroup);
    add(chooserPanel);
    unitGroup.setAlignmentY(TOP_ALIGNMENT);
    chooserPanel.setAlignmentY(TOP_ALIGNMENT);
}

From source file:QandE.LunarPhasesRB.java

public LunarPhasesRB() {
    //Create the phase selection and display panels.
    selectPanel = new JPanel();
    displayPanel = new JPanel();

    //Add various widgets to the sub panels.
    addWidgets();/*from w ww  .  j  a va  2 s .  co  m*/

    //Create the main panel to contain the two sub panels.
    mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    //Add the select and display panels to the main panel.
    mainPanel.add(selectPanel);
    mainPanel.add(displayPanel);
}

From source file:de.atomfrede.tools.evalutation.ui.ExceptionDialog.java

public JComponent createDetailsPanel() {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    exception.printStackTrace(pw);/*from w  ww . j  av a 2  s.  c o  m*/
    JTextArea textArea = new JTextArea(sw.toString());
    // textArea.setRows(10);

    JLabel label = new JLabel("Details:");

    JPanel panel = new JPanel(new BorderLayout(6, 6));
    panel.add(new JScrollPane(textArea));
    panel.add(label, BorderLayout.BEFORE_FIRST_LINE);
    label.setLabelFor(textArea);
    panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));

    setSize((int) panel.getPreferredSize().getWidth() + 20, getHeight() + 95);
    setMinimumSize(getSize());
    setMaximumSize(new Dimension(getSize().width, getSize().height + 150));
    panel.setMaximumSize(new Dimension((int) getMaximumSize().getWidth(), 150));
    return panel;
}