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: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;//ww w  .  ja  va2s.co  m

    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:events.ContainerEventDemo.java

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

    //Initialize an empty list of buttons.
    buttonList = new Vector<JButton>(10, 10);

    //Create all the components.
    addButton = new JButton("Add a button");
    addButton.setActionCommand(ADD);//w  ww.  ja  v  a2  s.  co m
    addButton.addActionListener(this);

    removeButton = new JButton("Remove a button");
    removeButton.setActionCommand(REMOVE);
    removeButton.addActionListener(this);

    buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.setPreferredSize(new Dimension(200, 75));
    buttonPanel.addContainerListener(this);

    display = new JTextArea();
    display.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(200, 75));

    clearButton = new JButton("Clear text area");
    clearButton.setActionCommand(CLEAR);
    clearButton.addActionListener(this);

    c.fill = GridBagConstraints.BOTH; //Fill entire cell.
    c.weighty = 1.0; //Button area and message area have equal height.
    c.gridwidth = GridBagConstraints.REMAINDER; //end of row
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    c.weighty = 0.0;
    gridbag.setConstraints(clearButton, c);
    add(clearButton);

    c.weightx = 1.0; //Add/remove buttons have equal width.
    c.gridwidth = 1; //NOT end of row
    gridbag.setConstraints(addButton, c);
    add(addButton);

    c.gridwidth = GridBagConstraints.REMAINDER; //end of row
    gridbag.setConstraints(removeButton, c);
    add(removeButton);

    c.weighty = 1.0; //Button area and message area have equal height.
    gridbag.setConstraints(buttonPanel, c);
    add(buttonPanel);

    setPreferredSize(new Dimension(400, 400));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:sim.util.media.chart.SeriesAttributes.java

void buildManipulators() {
    JButton removeButton = new JButton(I_CLOSE);
    removeButton.setPressedIcon(I_CLOSE_PRESSED);
    removeButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    removeButton.setBorderPainted(false);
    removeButton.setContentAreaFilled(false);
    removeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showOptionDialog(null, "Remove the Series " + getSeriesName() + "?", "Confirm",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    new Object[] { "Remove", "Cancel" }, null) == 0) // remove
                getGenerator().removeSeries(getSeriesIndex());
        }//from ww  w  .  j  ava 2  s. com
    });
    removeButton.setToolTipText("Remove this series");

    JButton upButton = new JButton(I_UP);
    upButton.setPressedIcon(I_UP_PRESSED);
    upButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    upButton.setBorderPainted(false);
    upButton.setContentAreaFilled(false);
    upButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), true);
        }
    });
    upButton.setToolTipText("Draw this series higher in the series order");

    JButton downButton = new JButton(I_DOWN);
    downButton.setPressedIcon(I_DOWN_PRESSED);
    downButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    downButton.setBorderPainted(false);
    downButton.setContentAreaFilled(false);
    downButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), false);
        }
    });
    downButton.setToolTipText("Draw this series lower in the series order");

    manipulators.add(removeButton);
    manipulators.add(upButton);
    manipulators.add(downButton);
}

From source file:edu.gmu.cs.sim.util.media.chart.SeriesAttributes.java

void buildManipulators() {
    JButton removeButton = new JButton(I_CLOSE);
    removeButton.setPressedIcon(I_CLOSE_PRESSED);
    removeButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    removeButton.setBorderPainted(false);
    removeButton.setContentAreaFilled(false);
    removeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showOptionDialog(null, "Remove the Series " + getSeriesName() + "?", "Confirm",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    new Object[] { "Remove", "Cancel" }, null) == 0) // remove
            {//from ww w. jav a 2  s.c o m
                getGenerator().removeSeries(getSeriesIndex());
            }
        }
    });
    removeButton.setToolTipText("Remove this series");

    JButton upButton = new JButton(I_UP);
    upButton.setPressedIcon(I_UP_PRESSED);
    upButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    upButton.setBorderPainted(false);
    upButton.setContentAreaFilled(false);
    upButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), true);
        }
    });
    upButton.setToolTipText("Draw this series higher in the series order");

    JButton downButton = new JButton(I_DOWN);
    downButton.setPressedIcon(I_DOWN_PRESSED);
    downButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    downButton.setBorderPainted(false);
    downButton.setContentAreaFilled(false);
    downButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), false);
        }
    });
    downButton.setToolTipText("Draw this series lower in the series order");

    manipulators.add(removeButton);
    manipulators.add(upButton);
    manipulators.add(downButton);
}

From source file:ListDemo.java

public ListDemo() {
    super(new BorderLayout());

    listModel = new DefaultListModel();
    listModel.addElement("Debbie Scott");
    listModel.addElement("Scott Hommel");
    listModel.addElement("Sharon Zakhour");

    // Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);/*from  w  ww.ja v  a2 s . c  o m*/
    list.addListSelectionListener(this);
    list.setVisibleRowCount(5);
    JScrollPane listScrollPane = new JScrollPane(list);

    JButton hireButton = new JButton(hireString);
    HireListener hireListener = new HireListener(hireButton);
    hireButton.setActionCommand(hireString);
    hireButton.addActionListener(hireListener);
    hireButton.setEnabled(false);

    fireButton = new JButton(fireString);
    fireButton.setActionCommand(fireString);
    fireButton.addActionListener(new FireListener());

    employeeName = new JTextField(10);
    employeeName.addActionListener(hireListener);
    employeeName.getDocument().addDocumentListener(hireListener);
    String name = listModel.getElementAt(list.getSelectedIndex()).toString();

    // Create a panel that uses BoxLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.add(fireButton);
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(new JSeparator(SwingConstants.VERTICAL));
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(employeeName);
    buttonPane.add(hireButton);
    buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    add(listScrollPane, BorderLayout.CENTER);
    add(buttonPane, BorderLayout.PAGE_END);
}

From source file:components.CheckBoxDemo.java

public CheckBoxDemo() {
    super(new BorderLayout());

    //Create the check boxes.
    chinButton = new JCheckBox("Chin");
    chinButton.setMnemonic(KeyEvent.VK_C);
    chinButton.setSelected(true);// w  w w  .  j a v  a  2s  .co m

    glassesButton = new JCheckBox("Glasses");
    glassesButton.setMnemonic(KeyEvent.VK_G);
    glassesButton.setSelected(true);

    hairButton = new JCheckBox("Hair");
    hairButton.setMnemonic(KeyEvent.VK_H);
    hairButton.setSelected(true);

    teethButton = new JCheckBox("Teeth");
    teethButton.setMnemonic(KeyEvent.VK_T);
    teethButton.setSelected(true);

    //Register a listener for the check boxes.
    chinButton.addItemListener(this);
    glassesButton.addItemListener(this);
    hairButton.addItemListener(this);
    teethButton.addItemListener(this);

    //Indicates what's on the geek.
    choices = new StringBuffer("cght");

    //Set up the picture label
    pictureLabel = new JLabel();
    pictureLabel.setFont(pictureLabel.getFont().deriveFont(Font.ITALIC));
    updatePicture();

    //Put the check boxes in a column in a panel
    JPanel checkPanel = new JPanel(new GridLayout(0, 1));
    checkPanel.add(chinButton);
    checkPanel.add(glassesButton);
    checkPanel.add(hairButton);
    checkPanel.add(teethButton);

    add(checkPanel, BorderLayout.LINE_START);
    add(pictureLabel, BorderLayout.CENTER);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:gui.TraitViewerDialog.java

private JPanel createControls() {
    model = new TraitTableModel();
    for (int i = 0; i < tFile.getNames().size(); i++) {
        model.addRow(new Object[] { i + 1, tFile.getEnabled().get(i), tFile.getNames().get(i) });
    }/*from  w w  w .java  2  s . c  o m*/

    table = new JTable(model);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getColumnModel().getColumn(0).setPreferredWidth(13);
    table.getColumnModel().getColumn(1).setPreferredWidth(30);
    table.getColumnModel().getColumn(2).setPreferredWidth(130);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(this);

    splits = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splits.setLeftComponent(new JScrollPane(table));

    splits.setDividerLocation(250);
    splits.setResizeWeight(0.5);
    splits.setRightComponent(new JPanel());
    JPanel p1 = new JPanel(new BorderLayout());
    p1.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
    p1.add(splits);

    return p1;
}

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 om*/

    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:com.game.ui.views.ItemPanel.java

public void doCommonStuffForContent() {
    JPanel panel1 = new JPanel();
    panel1.setAlignmentX(0);/*from w  w w  .j  a v  a  2 s  .co m*/
    panel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel1.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 0.2;
    c.gridwidth = 2;
    JLabel dtlLbl = new JLabel(type + "Details : ");
    dtlLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    panel1.add(dtlLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    panel1.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    panel1.add(name, c);
    if (ringPanel) {
        createComponentsForRing(panel1, c);
    } else if (armourPanel) {
        createComponentsForArmour(panel1, c);
    } else if (potionPanel) {
        createComponentsForPotion(panel1, c);
    } else if (treasurePanel) {
        createComponentsForTreasure(panel1, c);
    }
    c.gridx = 0;
    c.gridy = c.gridy + 1;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    panel1.add(submit, c);
    c.gridx = 0;
    c.gridy = c.gridy + 1;
    c.gridwidth = 2;
    c.weighty = 0;
    c.weightx = 1;
    validationMess = new JLabel("Pls enter all the fields or pls choose a " + type + " from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    panel1.add(validationMess, c);
    c.gridy++;
    c.weighty = 1;
    c.weightx = 1;
    panel1.add(new JPanel(), c);
    panel1.setBorder(LineBorder.createGrayLineBorder());
    add(panel1);
    add(Box.createVerticalGlue());
}

From source file:com.googlecode.vfsjfilechooser2.accessories.connection.ConnectionDialog.java

private void initCenterPanelComponents() {
    // create the panel
    this.centerPanel = new JPanel(new GridBagLayout());
    this.centerPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    // create the components
    this.hostnameLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.hostnameLabelText"));
    this.hostnameLabel.setForeground(Color.RED);
    this.hostnameTextField = new JTextField(25);

    this.portLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.portLabelText"));
    this.portTextField = new JFormattedTextField(NumberFormat.getInstance());
    this.isPortTextFieldDirty = false;

    this.protocolLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.protocolLabelText"));
    this.protocolModel = new DefaultComboBoxModel(Protocol.values());
    this.protocolList = new JComboBox(protocolModel);
    this.protocolList.setRenderer(new ProtocolRenderer());

    this.usernameLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.usernameLabelText"));
    this.usernameTextField = new JTextField(20);

    this.passwordLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.passwordLabelText"));
    this.passwordTextField = new JPasswordField(12);

    this.defaultRemotePathLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.pathLabelText"));
    this.defaultRemotePathTextField = new JTextField(20);

    // Add the components to the panel
    makeGridPanel(new Component[] { hostnameLabel, hostnameTextField, portLabel, portTextField, protocolLabel,
            protocolList, usernameLabel, usernameTextField, passwordLabel, passwordTextField,
            defaultRemotePathLabel, defaultRemotePathTextField });
}