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:components.DialogDemo.java

/** Creates the GUI shown inside the frame's content pane. */
public DialogDemo(JFrame frame) {
    super(new BorderLayout());
    this.frame = frame;
    customDialog = new CustomDialog(frame, "geisel", this);
    customDialog.pack();// w  w w  .j av a2 s . c o m

    //Create the components.
    JPanel frequentPanel = createSimpleDialogBox();
    JPanel featurePanel = createFeatureDialogBox();
    JPanel iconPanel = createIconDialogBox();
    label = new JLabel("Click the \"Show it!\" button" + " to bring up the selected dialog.", JLabel.CENTER);

    //Lay them out.
    Border padding = BorderFactory.createEmptyBorder(20, 20, 5, 20);
    frequentPanel.setBorder(padding);
    featurePanel.setBorder(padding);
    iconPanel.setBorder(padding);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Simple Modal Dialogs", null, frequentPanel, simpleDialogDesc); //tooltip text
    tabbedPane.addTab("More Dialogs", null, featurePanel, moreDialogDesc); //tooltip text
    tabbedPane.addTab("Dialog Icons", null, iconPanel, iconDesc); //tooltip text

    add(tabbedPane, BorderLayout.CENTER);
    add(label, BorderLayout.PAGE_END);
    label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
}

From source file:LookAndFeelDemo.java

public Component createComponents() {
    JButton button = new JButton("I'm a Swing button!");
    button.setMnemonic(KeyEvent.VK_I);
    button.addActionListener(this);
    label.setLabelFor(button);//w w  w.  j  a  v a 2  s.  co  m

    /*
     * An easy way to put space between a top-level container and its contents
     * is to put the contents in a JPanel that has an "empty" border.
     */
    JPanel pane = new JPanel(new GridLayout(0, 1));
    pane.add(button);
    pane.add(label);
    pane.setBorder(BorderFactory.createEmptyBorder(30, // top
            30, // left
            10, // bottom
            30) // right
    );

    return pane;
}

From source file:ComboBoxDemo2.java

public ComboBoxDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z",
            "EEE, MMM d, ''yy", "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" };

    currentPattern = patternExamples[0];

    //Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Enter the pattern string or");
    JLabel patternLabel2 = new JLabel("select one from the list:");

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setEditable(true);//w w w  . ja  v  a2s. c om
    patternList.addActionListener(this);

    //Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); //==
    // LEFT
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Lay out everything.
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternPanel.add(patternList);

    JPanel resultPanel = new JPanel(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    add(patternPanel);
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(resultPanel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    reformat();
}

From source file:CelsiusConverter2.java

private void addWidgets() {
    // Create widgets.

    ImageIcon icon = new ImageIcon("images/convert.gif", "Convert temperature");
    tempCelsius = new JTextField(2);
    celsiusLabel = new JLabel("Celsius", SwingConstants.LEFT);
    convertTemp = new JButton(icon);
    fahrenheitLabel = new JLabel("Fahrenheit", SwingConstants.LEFT);

    celsiusLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    fahrenheitLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    // Listen to events from Convert button.
    convertTemp.addActionListener(this);

    // Add widgets to container.
    converterPanel.add(tempCelsius);/*from   w  ww. ja va  2s.c  o m*/
    converterPanel.add(celsiusLabel);
    converterPanel.add(convertTemp);
    converterPanel.add(fahrenheitLabel);
}

From source file:com.jdom.util.patterns.mvp.swing.RadioButtonGroupDialog.java

private RadioButtonGroupDialog(Frame frame, Component locationComp, String labelText, String title,
        Collection<String> data, String initialValue, String longValue) {
    super(frame, title, true);

    final JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(this);

    final JButton setButton = new JButton("OK");
    setButton.setActionCommand("OK");
    setButton.addActionListener(this);
    getRootPane().setDefaultButton(setButton);

    ButtonGroup radioButtonGroup = new ButtonGroup();
    for (String option : data) {
        JRadioButton button = new JRadioButton(option);
        if (option.equals(initialValue)) {
            button.setSelected(true);//from w w  w .  ja  va  2s  .co  m
        }
        radioButtonGroup.add(button);
        panel.add(button);
    }

    JScrollPane listScroller = new JScrollPane(panel);
    listScroller.setPreferredSize(new Dimension(250, 80));
    listScroller.setAlignmentX(LEFT_ALIGNMENT);

    JPanel listPane = new JPanel();
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));

    if (!StringUtils.isEmpty(labelText)) {
        JLabel label = new JLabel(labelText);
        label.setText(labelText);
        listPane.add(label);
    }
    listPane.add(Box.createRigidArea(new Dimension(0, 5)));
    listPane.add(listScroller);
    listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(cancelButton);
    buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPane.add(setButton);

    Container contentPane = getContentPane();
    contentPane.add(listPane, BorderLayout.CENTER);
    contentPane.add(buttonPane, BorderLayout.PAGE_END);

    pack();
    setLocationRelativeTo(locationComp);
}

From source file:eu.delving.sip.actions.ImportAction.java

private void prepareDialog() {
    JButton cancel = new JButton("Cancel");
    cancel.addActionListener(new ActionListener() {
        @Override/*from   ww  w .  ja  va2 s .  c  om*/
        public void actionPerformed(ActionEvent actionEvent) {
            dialog.setVisible(false);
        }
    });
    JPanel bp = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    bp.add(cancel);
    JPanel p = new JPanel(new GridLayout(1, 0, 15, 15));
    p.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
    p.add(new JButton(chooseFileAction));
    p.add(new JButton(harvestAction));
    dialog.getContentPane().add(p, BorderLayout.CENTER);
    dialog.getContentPane().add(bp, BorderLayout.SOUTH);
    dialog.pack();
}

From source file:MouseEventDemo.java

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

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;/* ww w  .  ja  va  2 s . c o m*/
    c.weighty = 1.0;

    c.insets = new Insets(1, 1, 1, 1);
    blankArea = new BlankArea(new Color(0.98f, 0.97f, 0.85f));
    gridbag.setConstraints(blankArea, c);
    add(blankArea);

    c.insets = new Insets(0, 0, 0, 0);
    textArea = new JTextArea();
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(200, 75));
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    //Register for mouse events on blankArea and the panel.
    blankArea.addMouseListener(this);
    addMouseListener(this);

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

From source file:edu.ku.brc.ui.ProgressFrame.java

/**
 * @param title//from ww w  .  j  a  va2  s. co m
 * @param iconName
 */
protected void createUI(final String title, final String iconName) {
    PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,5px,p,5px,p,10px,p"));
    CellConstraints cc = new CellConstraints();

    overallProgress = new JProgressBar();
    processProgress = new JProgressBar();
    desc = createLabel("");
    closeBtn = createButton("Cancel");

    processProgress.setStringPainted(true);
    overallProgress.setStringPainted(true);

    desc.setHorizontalAlignment(SwingConstants.CENTER);
    builder.add(desc, cc.xywh(1, 1, 3, 1));

    builder.add(createLabel("Process:"), cc.xy(1, 3)); // I18N
    builder.add(processProgress, cc.xy(3, 3));

    builder.add(overallLbl = createLabel("Overall:"), cc.xy(1, 5)); // I18N
    builder.add(overallProgress, cc.xy(3, 5));

    builder.add(closeBtn, cc.xy(1, 7));

    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel mainPanel = new JPanel(new BorderLayout());
    if (StringUtils.isNotEmpty(iconName)) {
        PanelBuilder iconBldr = new PanelBuilder(
                new FormLayout("8px, f:p:g,130px,f:p:g", "8px,f:p:g,130px,f:p:g, 8px"));
        iconBldr.add(new JLabel(IconManager.getIcon(iconName)), cc.xy(3, 3));
        mainPanel.add(iconBldr.getPanel(), BorderLayout.WEST);
        mainPanel.add(builder.getPanel(), BorderLayout.CENTER);

    } else {
        mainPanel = builder.getPanel();
    }

    setContentPane(mainPanel);

    setSize(new Dimension(500, 125));

    setTitle(title);

    overallProgress.setIndeterminate(true);

    instance = this;
    closeBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            instance.setVisible(false);
            System.exit(0);
        }
    });

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    ImageIcon appIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$
    if (appIcon != null) {
        setIconImage(appIcon.getImage());
    }

    pack();
}

From source file:com.sshtools.common.ui.HostsTab.java

/**
 * Creates a new HostsTab object.//from w ww  . j a va2 s  . c o m
 *
 * @param hostKeyVerifier
 */
public HostsTab(AbstractKnownHostsKeyVerification hostKeyVerifier) {
    super();
    this.hostKeyVerifier = hostKeyVerifier;
    hosts = new JList(model = new HostsListModel());
    hosts.setVisibleRowCount(10);
    hosts.setCellRenderer(new HostRenderer());
    hosts.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            setAvailableActions();
        }
    });
    remove = new JButton("Remove", new ResourceIcon(REMOVE_ICON));
    remove.addActionListener(this);

    //deny = new JButton("Deny", new ResourceIcon(DENY_ICON));
    //deny.addActionListener(this);
    JPanel b = new JPanel(new GridBagLayout());
    b.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(0, 0, 4, 0);
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.weightx = 1.0;
    UIUtil.jGridBagAdd(b, remove, gbc, GridBagConstraints.REMAINDER);
    gbc.weighty = 1.0;

    //UIUtil.jGridBagAdd(b, deny, gbc, GridBagConstraints.REMAINDER);
    JPanel s = new JPanel(new BorderLayout());
    s.add(new JScrollPane(hosts), BorderLayout.CENTER);
    s.add(b, BorderLayout.EAST);

    IconWrapperPanel w = new IconWrapperPanel(new ResourceIcon(GLOBAL_ICON), s);

    //  This tab
    setLayout(new BorderLayout());
    add(w, BorderLayout.CENTER);
    setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    reset();
}

From source file:QandE.LunarPhasesRB.java

private void addWidgets() {
    /*/*from   w ww  .  ja  v a2  s .  c o  m*/
     * Create a label for displaying the moon phase images and
     * put a border around it.
     */
    phaseIconLabel = new JLabel();
    phaseIconLabel.setHorizontalAlignment(JLabel.CENTER);
    phaseIconLabel.setVerticalAlignment(JLabel.CENTER);
    phaseIconLabel.setVerticalTextPosition(JLabel.CENTER);
    phaseIconLabel.setHorizontalTextPosition(JLabel.CENTER);
    phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0),
            phaseIconLabel.getBorder()));

    //Create radio buttons with lunar phase choices.
    JRadioButton newButton = new JRadioButton("New");
    newButton.setActionCommand("0");
    newButton.setSelected(true);

    JRadioButton waxingCrescentButton = new JRadioButton("Waxing Crescent");
    waxingCrescentButton.setActionCommand("1");

    JRadioButton firstQuarterButton = new JRadioButton("First Quarter");
    firstQuarterButton.setActionCommand("2");

    JRadioButton waxingGibbousButton = new JRadioButton("Waxing Gibbous");
    waxingGibbousButton.setActionCommand("3");

    JRadioButton fullButton = new JRadioButton("Full");
    fullButton.setActionCommand("4");

    JRadioButton waningGibbousButton = new JRadioButton("Waning Gibbous");
    waningGibbousButton.setActionCommand("5");

    JRadioButton thirdQuarterButton = new JRadioButton("Third Quarter");
    thirdQuarterButton.setActionCommand("6");

    JRadioButton waningCrescentButton = new JRadioButton("Waning Crescent");
    waningCrescentButton.setActionCommand("7");

    // Create a button group and add the radio buttons.
    ButtonGroup group = new ButtonGroup();
    group.add(newButton);
    group.add(waxingCrescentButton);
    group.add(firstQuarterButton);
    group.add(waxingGibbousButton);
    group.add(fullButton);
    group.add(waningGibbousButton);
    group.add(thirdQuarterButton);
    group.add(waningCrescentButton);

    // Display the first image.
    phaseIconLabel.setIcon(new ImageIcon("images/image0.jpg"));
    phaseIconLabel.setText("");

    //Make the radio buttons appear in a center-aligned column.
    selectPanel.setLayout(new BoxLayout(selectPanel, BoxLayout.PAGE_AXIS));
    selectPanel.setAlignmentX(Component.CENTER_ALIGNMENT);

    //Add a border around the select panel.
    selectPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Select Phase"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Add a border around the display panel.
    displayPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Display Phase"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Add image and moon phases radio buttons to select panel.
    displayPanel.add(phaseIconLabel);
    selectPanel.add(newButton);
    selectPanel.add(waxingCrescentButton);
    selectPanel.add(firstQuarterButton);
    selectPanel.add(waxingGibbousButton);
    selectPanel.add(fullButton);
    selectPanel.add(waningGibbousButton);
    selectPanel.add(thirdQuarterButton);
    selectPanel.add(waningCrescentButton);

    //Listen to events from the radio buttons.
    newButton.addActionListener(this);
    waxingCrescentButton.addActionListener(this);
    firstQuarterButton.addActionListener(this);
    waxingGibbousButton.addActionListener(this);
    fullButton.addActionListener(this);
    waningGibbousButton.addActionListener(this);
    thirdQuarterButton.addActionListener(this);
    waningCrescentButton.addActionListener(this);

}