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

/**
 * Initialises the {@link JDialog} for the {@link JComponent}.
 * //from  w w  w .  j  av a  2s  .  c o  m
 * @param dialog
 * @param component
 * @param parentComponent
 */
private static void initDialog(final JDialog dialog, final JComponent component,
        final Component parentComponent) {
    dialog.setResizable(true);
    dialog.setComponentOrientation(component.getComponentOrientation());
    Container contentPane = dialog.getContentPane();

    contentPane.setLayout(new BorderLayout());
    contentPane.add(component, BorderLayout.CENTER);

    final int buttonWidth = 75;

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4));

    buttonPanel.add(Box.createHorizontalGlue());

    @SuppressWarnings("serial")
    final Action closeAction = new AbstractAction("Close") {
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };

    final JButton button = new JButton(closeAction);
    fixWidth(button, buttonWidth);
    buttonPanel.add(button);

    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
        if (supportsWindowDecorations) {
            dialog.setUndecorated(true);
            component.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        }
    }
    dialog.pack();
    dialog.setLocationRelativeTo(parentComponent);
    WindowAdapter adapter = new WindowAdapter() {
        //         private boolean gotFocus = false;
        public void windowClosing(WindowEvent we) {
            fireAction(we.getSource(), closeAction, "close");
        }
    };
    dialog.addWindowListener(adapter);
    dialog.addWindowFocusListener(adapter);
}

From source file:Main.java

/**
 * @param panel/*from   w  w w .  j  a v  a 2 s  .c o  m*/
 * @return pre-configured constraints
 */
public static GridBagConstraints initPanel(JPanel panel) {
    panel.setLayout(new GridBagLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    GridBagConstraints gb = new GridBagConstraints();
    gb.gridx = 0;
    gb.gridy = 0;
    gb.insets = new Insets(2, 2, 2, 2);
    return gb;
}

From source file:Main.java

public Main() {
    JPanel borderLayoutPanel = new JPanel(new BorderLayout());
    borderLayoutPanel.setBorder(BorderFactory.createTitledBorder("BorderLayout Panel"));
    borderLayoutPanel.add(createGridPanel(), BorderLayout.CENTER);

    JPanel flowLayoutPanel = new JPanel(new FlowLayout());
    flowLayoutPanel.setBorder(BorderFactory.createTitledBorder("FlowLayout Panel"));
    flowLayoutPanel.add(createGridPanel());

    setBorder(BorderFactory.createEmptyBorder(GAP, GAP, GAP, GAP));
    setLayout(new GridLayout(1, 0, GAP, 0));
    add(borderLayoutPanel);//  w  w  w  .j  av a2s. c  om
    add(flowLayoutPanel);
}

From source file:Main.java

/**
 * @param scrollPane/*  w  w  w  .j a v  a  2 s .  c  o m*/
 * @return
 */
public static GridBagConstraints initScrollPane(JScrollPane scrollPane) {
    scrollPane.setLayout(new ScrollPaneLayout());
    scrollPane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    GridBagConstraints gb = new GridBagConstraints();
    gb.gridx = 0;
    gb.gridy = 0;
    gb.insets = new Insets(2, 2, 2, 2);
    return gb;
}

From source file:Main.java

public JPanel createUI() {
    intro.setLabelFor(name);//from  w  w  w  . j a  va  2s.c  o  m
    final JButton button = new JButton("Pick a new name...");
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20));
    intro.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    name.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    button.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    panel.add(intro);
    panel.add(Box.createVerticalStrut(5));
    panel.add(name);
    panel.add(Box.createRigidArea(new Dimension(150, 10)));
    panel.add(button);
    return panel;
}

From source file:Main.java

public Main() {
    super(new BorderLayout());
    textArea.setEditable(false);//from  w w w .j  a  v a  2s  .  c  o  m

    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(400, 250));
    add(scrollPane, BorderLayout.CENTER);

    textArea.addMouseWheelListener(this);

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

From source file:Main.java

private JPanel createComboLabelPanel(int index, JComboBox<ComboColor> combo) {
    JPanel panel = new JPanel();
    JLabel label = new JLabel(SIGNAL + " " + index);
    label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    label.setOpaque(true);/*from w  ww  .j  ava2 s  . co  m*/
    combo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            ComboColor cColor = (ComboColor) combo.getSelectedItem();
            label.setBackground(cColor.getColor());
        }
    });

    panel.add(label);
    panel.add(combo);
    return panel;
}

From source file:Main.java

public Main() {
    super(new BorderLayout());
    textArea.setEditable(false);// ww w . ja v  a 2 s.c om

    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(400, 250));
    add(scrollPane, BorderLayout.CENTER);
    textArea.append("This text area displays information " + "about its mouse wheel events." + newline);

    textArea.addMouseWheelListener(this);

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

From source file:com.catexpress.gui.tools.AutoCompletarCellRenderer.java

@Override
public Component getListCellRendererComponent(JList list, Cliente cliente, int index, boolean isSelected,
        boolean cellHasFocus) {
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    if (cliente == null) {
        setText("Ningun resultado encontrado");
        return this;
    }//from www. ja va2 s  . c  om

    String replace = "<html>";

    if (StringUtils.containsIgnoreCase(String.valueOf(cliente.getId()), regex.getText())) {
        replace += String.valueOf(cliente.getId()).replaceAll("(?i)" + regex.getText(),
                "<font color='" + MATCH_COLOR + "'>" + regex.getText() + "</font>");
    } else {
        replace += cliente.getId();
    }

    if (StringUtils.containsIgnoreCase(cliente.getNombre(), regex.getText())) {
        replace += " - " + cliente.getNombre().replaceAll("(?i)" + regex.getText(),
                "<font color='" + MATCH_COLOR + "'>" + regex.getText() + "</font>");
    } else {
        replace += " - " + cliente.getNombre();
    }

    if (StringUtils.containsIgnoreCase(cliente.getApPaterno(), regex.getText())) {
        replace += " " + cliente.getApPaterno().replaceAll("(?i)" + regex.getText(),
                "<font color='" + MATCH_COLOR + "'>" + regex.getText() + "</font>");
    } else {
        replace += " " + cliente.getApPaterno();
    }

    if (StringUtils.containsIgnoreCase(cliente.getApMaterno(), regex.getText())) {
        replace += " " + cliente.getApMaterno().replaceAll("(?i)" + regex.getText(),
                "<font color='" + MATCH_COLOR + "'>" + regex.getText() + "</font>");
    } else {
        replace += " " + cliente.getApMaterno();
    }

    setText(replace);
    return this;
}

From source file:Main.java

public ArrowButton(int direction, int arrowCount, int arrowSize) {
    setMargin(new Insets(0, 2, 0, 2));
    setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    this.direction = direction;
    this.arrowCount = arrowCount;
    this.arrowSize = arrowSize;
}