Example usage for javax.swing.border EmptyBorder EmptyBorder

List of usage examples for javax.swing.border EmptyBorder EmptyBorder

Introduction

In this page you can find the example usage for javax.swing.border EmptyBorder EmptyBorder.

Prototype

public EmptyBorder(int top, int left, int bottom, int right) 

Source Link

Document

Creates an empty border with the specified insets.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Sample Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border emptyBorder = new EmptyBorder(5, 10, 5, 10);

    JLabel aLabel = new JLabel("Bevel");
    aLabel.setBorder(emptyBorder);/*from w  w  w  . j  a va  2s . c  o m*/
    aLabel.setHorizontalAlignment(JLabel.CENTER);

    frame.add(aLabel);
    frame.setSize(400, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JPanel ui = new JPanel(new BorderLayout(2, 2));
    ui.setBorder(new EmptyBorder(4, 4, 4, 4));

    JPanel controls = new JPanel(new BorderLayout(2, 2));
    ui.add(controls, BorderLayout.PAGE_START);
    String s = new String(Character.toChars(8594));
    String[] items = { "Choice: right " + s + " arrow" };
    JComboBox cb = new JComboBox(items);
    controls.add(cb, BorderLayout.CENTER);
    controls.add(new JButton("Button"), BorderLayout.LINE_END);

    JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JTextArea(4, 40), new JTextArea(4, 40));

    ui.add(sp, BorderLayout.CENTER);

    JFrame f = new JFrame("Stretch Combo Layout");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setContentPane(ui);//www.j ava  2  s  .c o  m
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout());
    gui.setBorder(new EmptyBorder(2, 3, 2, 3));

    JPanel textPanel = new JPanel(new BorderLayout(5, 5));
    textPanel.add(new JScrollPane(new JTextArea("Top Text", 3, 20)), BorderLayout.PAGE_START);
    textPanel.add(new JScrollPane(new JTextArea("Main Text", 10, 10)));
    gui.add(textPanel, BorderLayout.CENTER);

    JPanel buttonCenter = new JPanel(new GridBagLayout());
    buttonCenter.setBorder(new EmptyBorder(5, 5, 5, 5));
    JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 5, 5));
    for (int ii = 1; ii < 6; ii++) {
        buttonPanel.add(new JButton("Button " + ii));
    }// w  ww  .j av a 2 s  .com

    buttonCenter.add(buttonPanel);

    gui.add(buttonCenter, BorderLayout.LINE_END);

    JFrame f = new JFrame("Demo");
    f.add(gui);

    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    f.setLocationByPlatform(true);

    f.pack();

    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    int specificX = 40;
    int specificY = 20;

    JPanel gui = new JPanel(new BorderLayout());
    JTextField tf = new JTextField(10);
    JPanel borderPanel = new JPanel(new GridLayout());
    borderPanel.add(tf);/*ww  w  .ja va  2 s .  c om*/
    borderPanel.setBorder(new EmptyBorder(specificX, specificY, specificX, specificY));
    borderPanel.setBackground(Color.GREEN);
    gui.add(borderPanel);

    JOptionPane.showMessageDialog(null, gui);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);/*from  w  w  w .  j a  va2  s  .  c  o  m*/

    JDialog dialog = new JDialog(frame, "Dialog", true);

    JPanel mainGui = new JPanel(new BorderLayout());
    mainGui.setBorder(new EmptyBorder(20, 20, 20, 20));
    mainGui.add(new JLabel("Contents go here"), BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel(new FlowLayout());
    mainGui.add(buttonPanel, BorderLayout.SOUTH);

    JButton close = new JButton("Close");
    close.addActionListener(e -> dialog.setVisible(false));

    buttonPanel.add(close);

    frame.setVisible(true);

    dialog.setContentPane(mainGui);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel statusBar = new JPanel(new FlowLayout(FlowLayout.LEFT));
    statusBar.setBorder(new CompoundBorder(new LineBorder(Color.DARK_GRAY), new EmptyBorder(4, 4, 4, 4)));
    final JLabel status = new JLabel();
    statusBar.add(status);/*  ww  w  . j a v a 2 s .co  m*/

    JLabel content = new JLabel("Content in the middle");
    content.setHorizontalAlignment(JLabel.CENTER);

    final JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(content);
    frame.add(statusBar, BorderLayout.SOUTH);

    frame.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            status.setText(frame.getWidth() + "x" + frame.getHeight());
        }
    });

    frame.setBounds(20, 20, 200, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel topPanel = new JPanel();
    topPanel.setPreferredSize(new Dimension(200, 200));
    topPanel.setBackground(Color.WHITE);

    JTextArea chatArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(chatArea);

    JPanel mainPanel = new JPanel(new BorderLayout(5, 5));
    mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    mainPanel.add(topPanel, BorderLayout.CENTER);
    mainPanel.add(scrollPane, BorderLayout.SOUTH);

    chatArea.getDocument().addDocumentListener(new DocumentListener() {

        @Override// w  w w.ja  v a2 s.  c om
        public void insertUpdate(DocumentEvent e) {
            updateLineCount();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateLineCount();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateLineCount();
        }

        private void updateLineCount() {
            int lineCount = chatArea.getLineCount();
            if (lineCount <= 4) {
                chatArea.setRows(lineCount);
                mainPanel.revalidate();
            }
        }
    });

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(mainPanel);
    f.pack();
    f.setVisible(true);
}

From source file:BorderLayoutExample.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JMenuBar menubar = new JMenuBar();
    JMenu file = new JMenu("File");

    menubar.add(file);//  www .  j  av  a2  s .c  o m
    f.setJMenuBar(menubar);

    JToolBar toolbar = new JToolBar();
    toolbar.setFloatable(false);

    JButton bexit = new JButton(new ImageIcon("exit.png"));
    bexit.setBorder(new EmptyBorder(0, 0, 0, 0));
    toolbar.add(bexit);

    f.add(toolbar, BorderLayout.NORTH);

    JToolBar vertical = new JToolBar(JToolBar.VERTICAL);
    vertical.setFloatable(false);
    vertical.setMargin(new Insets(10, 5, 5, 5));

    JButton selectb = new JButton(new ImageIcon("a.png"));
    selectb.setBorder(new EmptyBorder(3, 0, 3, 0));

    JButton freehandb = new JButton(new ImageIcon("b.png"));
    freehandb.setBorder(new EmptyBorder(3, 0, 3, 0));
    JButton shapeedb = new JButton(new ImageIcon("c.png"));
    shapeedb.setBorder(new EmptyBorder(3, 0, 3, 0));

    vertical.add(selectb);
    vertical.add(freehandb);
    vertical.add(shapeedb);

    f.add(vertical, BorderLayout.WEST);
    f.add(new JTextArea(), BorderLayout.CENTER);

    JLabel statusbar = new JLabel(" Statusbar");
    statusbar.setPreferredSize(new Dimension(-1, 22));
    statusbar.setBorder(LineBorder.createGrayLineBorder());
    f.add(statusbar, BorderLayout.SOUTH);
    f.setSize(350, 300);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel ui = new JPanel(new BorderLayout(4, 4));
    ui.setBorder(new EmptyBorder(6, 6, 6, 6));

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.LEADING));
    ui.add(controls, BorderLayout.PAGE_START);
    int s = 100;/* w w  w.  ja va  2 s.  c om*/
    Dimension[] sizes = { new Dimension(s * 4, s * 2), new Dimension(s * 6, s * 3),
            new Dimension(s * 8, s * 4) };
    final JComboBox cb = new JComboBox(sizes);
    controls.add(cb);
    final JPanel[] panels = new JPanel[sizes.length];
    for (int ii = 0; ii < sizes.length; ii++) {
        Dimension d = sizes[ii];
        BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
        JPanel p = new JPanel(new GridLayout());
        JLabel l = new JLabel(new ImageIcon(bi));
        p.add(l);
        panels[ii] = p;
    }
    ItemListener sizeListener = new ItemListener() {

        JPanel current = panels[0];

        @Override
        public void itemStateChanged(ItemEvent e) {
            JPanel next = panels[cb.getSelectedIndex()];
            swapComponentsAndResizeUI(ui, current, next);
            current = next;
        }
    };
    cb.addItemListener(sizeListener);

    ui.add(panels[0], BorderLayout.CENTER);

    JFrame f = new JFrame("Three Sized Panels");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setContentPane(ui);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    final ConfirmDialog dialog = new ConfirmDialog(f);
    final JTree tree = new JTree();
    tree.setVisibleRowCount(5);//from   ww  w. j av a  2s .  co m
    final JScrollPane treeScroll = new JScrollPane(tree);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton b = new JButton("Choose Tree Item");
    b.addActionListener(e -> {
        int result = dialog.showConfirmDialog(treeScroll, "Choose an item");
        if (result == ConfirmDialog.OK_OPTION) {
            System.out.println(tree.getSelectionPath());
        } else {
            System.out.println("User cancelled");
        }
    });
    JPanel p = new JPanel(new BorderLayout());
    p.add(b);
    p.setBorder(new EmptyBorder(50, 50, 50, 50));
    f.setContentPane(p);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

}