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:Main.java

public static void main(String[] args) throws Exception {
    JLabel label = new JLabel("java2s.com");

    JPanel panel = new JPanel();
    panel.add(label);//w ww. j av a  2s  . c  om
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    JOptionPane.showMessageDialog(null, panel);

}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Empty Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border emptyBorder = BorderFactory.createEmptyBorder(20, 20, 0, 0);
    JButton emptyButton = new JButton("With Empty");
    emptyButton.setBorder(emptyBorder);// w ww.j  av  a2  s.  c  om
    JButton nonemptyButton = new JButton("Without Empty");
    Container contentPane = frame.getContentPane();
    contentPane.add(emptyButton, BorderLayout.NORTH);
    contentPane.add(nonemptyButton, BorderLayout.SOUTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.setVisible(true);
}

From source file:AnEmptyBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Empty Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border emptyBorder = BorderFactory.createEmptyBorder(20, 20, 0, 0);
    JButton emptyButton = new JButton("With Empty");
    emptyButton.setBorder(emptyBorder);/*  www .j a va 2  s.  c  o  m*/
    JButton nonemptyButton = new JButton("Without Empty");
    Container contentPane = frame.getContentPane();
    contentPane.add(emptyButton, BorderLayout.NORTH);
    contentPane.add(nonemptyButton, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:AnEmptyBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Empty Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Border emptyBorder = BorderFactory.createEmptyBorder(20, 20, 0, 0);
    JButton emptyButton = new JButton("With Empty");
    emptyButton.setBorder(emptyBorder);/*from   ww w . j  a v a 2s . c  o  m*/

    JButton nonemptyButton = new JButton("Without Empty");

    Container contentPane = frame.getContentPane();
    contentPane.add(emptyButton, BorderLayout.NORTH);
    contentPane.add(nonemptyButton, BorderLayout.SOUTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.setVisible(true);
}

From source file:TextArea.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextArea area = new JTextArea();
    area.setLineWrap(true);/* w  w w.  ja v  a2  s .c  o  m*/
    area.setWrapStyleWord(true);
    area.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    f.add(new JScrollPane(area));
    f.setSize(new Dimension(350, 300));

    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JFrame frame = new JFrame("Test");
    JPanel panel = new JPanel();
    JLabel label = new JLabel("CenteredJLabel");

    panel.setLayout(new GridBagLayout());
    panel.add(label);/*w ww.  ja v a 2 s.  c om*/
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.setSize(400, 300);
    frame.setVisible(true);

}

From source file:JColorChooserWithCustomPreviewPanel.java

public static void main(String[] a) {

    final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER);
    previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48));
    previewLabel.setSize(previewLabel.getPreferredSize());
    previewLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0));

    JColorChooser colorChooser = new JColorChooser();
    colorChooser.setPreviewPanel(previewLabel);

    JDialog d = colorChooser.createDialog(null, "", true, colorChooser, null, null);

    d.setVisible(true);//  w ww.  ja  v  a 2  s  .  co  m
}

From source file:MainClass.java

public static void main(String[] a) {

    final JColorChooser colorChooser = new JColorChooser();
    final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER);
    previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48));
    previewLabel.setSize(previewLabel.getPreferredSize());
    previewLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0));
    colorChooser.setPreviewPanel(previewLabel);

    ActionListener okActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("OK Button");
            System.out.println(colorChooser.getColor());
        }//from  ww  w . j a v a2 s .c  om
    };

    ActionListener cancelActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Cancel Button");
        }
    };

    final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true, colorChooser,
            okActionListener, cancelActionListener);

    dialog.setVisible(true);
}

From source file:MyLabel.java

public static void main(String[] args) {
    String lyrics = "<html>Line<br>line<br>line</html>";

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout(10, 10));

    JLabel label = new JLabel(lyrics);
    label.setFont(new Font("Georgia", Font.PLAIN, 14));
    label.setForeground(new Color(50, 50, 25));

    panel.add(label, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    JFrame f = new JFrame();
    f.add(panel);// w  ww  .  j  a  v a 2 s. c  o  m
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String[] data = { "alist", "arithmetic", "ASCIInumbers", "A", "B", "list", "C", "D", "E", "numeral", "G",
            "F" };

    JCheckBox[] checkBox;//w  ww . j ava  2  s. c om
    JButton submitButton;
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    JPanel contentPane = new JPanel();
    contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(5, 5));

    checkBox = new JCheckBox[data.length];
    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new GridLayout(0, 4, 5, 5));
    for (int i = 0; i < data.length; i++) {
        checkBox[i] = new JCheckBox(data[i]);
        centerPanel.add(checkBox[i]);
    }
    contentPane.add(centerPanel, BorderLayout.CENTER);

    JPanel footerPanel = new JPanel();
    submitButton = new JButton("Submit");
    footerPanel.add(submitButton);
    contentPane.add(footerPanel, BorderLayout.PAGE_END);

    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}