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 boolean showModalDialogOnEDT(JComponent contents, String title, String okButtonMessage,
        String cancelButtonMessage, ModalityType modalityType, final boolean systemExitOnDisposed) {

    class Result {
        boolean OK = false;
    }//from  w  w  w. j av a  2  s  .c  o m
    final Result result = new Result();

    final JDialog dialog = new JDialog((Frame) null, title, true) {
        @Override
        public void dispose() {
            super.dispose();
            if (systemExitOnDisposed) {
                System.exit(0);
            }
        }
    };

    // ensure it doesn't block other dialogs
    if (modalityType != null) {
        dialog.setModalityType(modalityType);
    }

    // See http://stackoverflow.com/questions/1343542/how-do-i-close-a-jdialog-and-have-the-window-event-listeners-be-notified
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
    if (okButtonMessage != null) {
        buttonPane.add(new JButton(new AbstractAction(okButtonMessage) {

            @Override
            public void actionPerformed(ActionEvent e) {
                result.OK = true;
                dialog.dispose();
            }
        }));
    }

    if (cancelButtonMessage != null) {
        buttonPane.add(new JButton(new AbstractAction(cancelButtonMessage) {

            @Override
            public void actionPerformed(ActionEvent e) {
                dialog.dispose();
            }
        }));
    }

    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BorderLayout());
    panel.add(contents, BorderLayout.CENTER);
    panel.add(buttonPane, BorderLayout.SOUTH);

    // startup frame
    dialog.getContentPane().add(panel);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.pack();

    // This hopefully centres the dialog even though the parameter is null 
    // see http://stackoverflow.com/questions/213266/how-do-i-center-a-jdialog-on-screen
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);

    return result.OK;
}

From source file:com.vrane.metaGlacier.gui.SNSTopicDialog.java

SNSTopicDialog() {
    super(Main.frame, true);
    JPanel mainPanel = new JPanel(new GridLayout(4, 2));
    final JTextField topicNameJT = new JTextField(10);
    final JTextField emailJT = new JTextField(10);
    final JButton subscribeButton = new JButton("subscribe");

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

    mainPanel.add(new JLabel("topic name"));
    mainPanel.add(topicNameJT);//w  w  w . j a v  a 2 s . com

    mainPanel.add(new JLabel("email"));
    mainPanel.add(emailJT);

    final String metadata_account_email = Main.frame.getMPCUser();
    if (metadata_account_email != null) {
        emailJT.setText(metadata_account_email);
    }

    mainPanel.add(new JLabel());
    mainPanel.add(subscribeButton);
    subscribeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            final String email = emailJT.getText();
            final String name = topicNameJT.getText();
            boolean success = false;

            if (!EmailValidator.getInstance().isValid(email)) {
                JOptionPane.showMessageDialog(null, "Invalid email address");
                return;
            }
            try {
                success = new SNSTopic().createTopic(name, email);
            } catch (Exception ex) {
                LGR.log(Level.SEVERE, null, ex);
            }
            if (success) {
                JOptionPane.showMessageDialog(null, "Please check your email to confirm");
                dispose();
                return;
            }
            JOptionPane.showMessageDialog(null, "Error subscribing");
        }
    });
    add(mainPanel);
    pack();
    setLocationRelativeTo(Main.frame);
    setVisible(true);
}

From source file:Main.java

public CustomPanel(Color c) {
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10),
            BorderFactory.createLineBorder(Color.black, 1)));

    setBackground(c);//w w w  .  j  a v a 2s.  c o  m
}

From source file:com.github.fritaly.dualcommander.Utils.java

public static Border createEmptyBorder(int space) {
    return BorderFactory.createEmptyBorder(space, space, space, space);
}

From source file:com.vrane.metaGlacier.gui.MetaDataSignUpDialog.java

MetaDataSignUpDialog() {
    super(Main.frame, true);
    JPanel signUpPanel = new JPanel(new GridLayout(4, 2));
    final JTextField nameJT = new JTextField(10);
    final JTextField emailJT = new JTextField(10);
    final JTextField emailJT1 = new JTextField(10);
    final JButton signUpButton = new JButton("Sign up");

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

    signUpPanel.add(new JLabel("name (optional)"));
    signUpPanel.add(nameJT);//from   w w  w.  j a  v  a  2s  .  c  o m

    signUpPanel.add(new JLabel("email"));
    signUpPanel.add(emailJT);

    signUpPanel.add(new JLabel("email again"));
    signUpPanel.add(emailJT1);

    signUpPanel.add(new JLabel());

    signUpPanel.add(signUpButton);
    signUpButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            final String email = emailJT.getText();
            final String email1 = emailJT1.getText();
            final String name = nameJT.getText();
            boolean success = false;

            if (!email.equals(email1)) {
                JOptionPane.showMessageDialog(null, "Email addresses do not match");
                return;
            }
            if (!EmailValidator.getInstance().isValid(email)) {
                JOptionPane.showMessageDialog(null, "Invalid email address");
                return;
            }
            try {
                success = new SignUp().signup(email, name);
            } catch (SDKException ex) {
                LGR.log(Level.SEVERE, null, ex);
            }
            if (success) {
                JOptionPane.showMessageDialog(null, "Please check your email to confirm");
                dispose();
                return;
            }
            JOptionPane.showMessageDialog(null, "Error signing up");
        }
    });
    add(signUpPanel);
    pack();
    setLocationRelativeTo(Main.frame);
    setVisible(true);
}

From source file:com.intuit.tank.tools.debugger.RequestResponsePanel.java

public void init() {
    JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
    pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    requestTA = new RTextArea();
    requestTA.setEditable(false);/*from   www .ja v a2s. c o m*/
    requestTA.setAutoscrolls(true);
    requestTA.setHighlightCurrentLine(false);
    JScrollPane sp1 = new JScrollPane(requestTA, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    sp1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    JPanel reqPane = new JPanel(new BorderLayout());
    // JPanel titlePanel = new JPanel(new BorderLayout());
    // titlePanel.add(BorderLayout.WEST, new JLabel("Request:"));
    // JButton saveBT = new JButton(parent.getDebuggerActions().getSaveReqResponseAction());
    // saveBT.setText("");
    // titlePanel.add(BorderLayout.EAST, saveBT);
    reqPane.add(BorderLayout.NORTH, new JLabel("Request:"));
    reqPane.add(BorderLayout.CENTER, sp1);
    pane.setTopComponent(reqPane);

    responseTA = new RTextArea();
    responseTA.setEditable(false);
    responseTA.setAutoscrolls(true);
    responseTA.setHighlightCurrentLine(false);
    JScrollPane sp2 = new JScrollPane(responseTA, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    sp2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    JPanel responsePane = new JPanel(new BorderLayout());
    responsePane.add(BorderLayout.NORTH, new JLabel("Response:"));
    responsePane.add(BorderLayout.CENTER, sp2);
    pane.setBottomComponent(responsePane);
    pane.setDividerLocation(0.5D);
    pane.setResizeWeight(0.5D);

    add(pane, BorderLayout.CENTER);
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.add(parent.getDebuggerActions().getSaveReqResponseAction());
    requestTA.setPopupMenu(popupMenu);
    responseTA.setPopupMenu(popupMenu);
}

From source file:Main.java

/**
 * Sets up the given window content pane by setting its border to provide a
 * good default spacer, and setting the content pane to the given components.
 * /* www  .  j  a v  a2  s .c  o m*/
 * @param aWindow
 *          the window to setup, cannot be <code>null</code>;
 * @param aCenterComponent
 *          the component that should appear at the center of the dialog;
 * @param aButtonPane
 *          the component that should appear at the bottom of the dialog
 * @param defaultButton
 *          the default button for this dialog; can be null for "none".
 * @see javax.swing.JRootPane#setDefaultButton(javax.swing.JButton)
 */
public static void setupWindowContentPane(final Window aWindow, final Component aCenterComponent,
        final Component aButtonPane, final JButton defaultButton) {
    final JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setBorder(BorderFactory.createEmptyBorder(DIALOG_PADDING, DIALOG_PADDING, //
            DIALOG_PADDING, DIALOG_PADDING));

    contentPane.add(aCenterComponent, BorderLayout.CENTER);
    contentPane.add(aButtonPane, BorderLayout.PAGE_END);

    if (aWindow instanceof JDialog) {
        ((JDialog) aWindow).setContentPane(contentPane);
        ((JDialog) aWindow).getRootPane().setDefaultButton(defaultButton);
    } else if (aWindow instanceof JFrame) {
        ((JFrame) aWindow).setContentPane(contentPane);
        ((JFrame) aWindow).getRootPane().setDefaultButton(defaultButton);
    }
    aWindow.pack();
}

From source file:com.tencent.wstt.apt.chart.PieChart.java

public PieChart() {
    super(new BorderLayout());
    chart = createChart();/*from   w  w  w.  ja v a  2 s . c o m*/
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    this.add(chartPanel);
}

From source file:com.game.ui.views.UserDialog.java

public UserDialog(String message, JFrame frame) {
    setLayout(new BorderLayout(5, 5));
    setModalityType(ModalityType.APPLICATION_MODAL);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setResizable(false);/*  www  .ja v a  2 s  .  c  om*/
    ImageIcon icon = null;
    try {
        icon = GameUtils.shrinkImage("warning.gif", 30, 30);
    } catch (IOException e) {
        System.out.println("Dialog : showDialogForMap(): Exception occured :" + e);
        e.printStackTrace();
    }
    JPanel panel = new JPanel();
    JLabel label = new JLabel(icon);
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    label.setText(message);
    label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    label.setHorizontalAlignment(0);
    panel.add(label);
    add(panel, BorderLayout.NORTH);
    JPanel contentPanel = new JPanel();
    contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
    txt = new JTextField();
    txt.setPreferredSize(new Dimension(150, 30));
    txt.setAlignmentX(.5f);
    txt.setMaximumSize(new Dimension(150, 30));
    contentPanel.add(txt);
    contentPanel.add(Box.createVerticalStrut(10));
    JButton btn = new JButton("Submit.");
    btn.setAlignmentX(.5f);
    btn.setPreferredSize(new Dimension(50, 25));
    btn.addActionListener(this);
    validationMess = new JLabel("All fields are mandatory");
    validationMess.setVisible(false);
    validationMess.setForeground(Color.red);
    validationMess.setAlignmentX(.5f);
    contentPanel.add(btn);
    contentPanel.add(Box.createVerticalStrut(10));
    contentPanel.add(validationMess);
    contentPanel.add(Box.createVerticalGlue());
    add(contentPanel, BorderLayout.CENTER);
    pack();
    setSize(new Dimension(300, 200));
    setLocationRelativeTo(frame);
    setVisible(true);
}

From source file:ch.zhaw.ias.dito.ui.util.SingleHistogramPanel.java

public SingleHistogramPanel(Matrix m) {
    super(new BorderLayout());
    this.m = m;// ww  w . j  a  v a  2 s .c  om
    this.chart = createChart();
    this.chartPanel = new ChartPanel(this.chart);

    Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createEtchedBorder());
    this.chartPanel.setBorder(border);
    add(this.chartPanel, BorderLayout.CENTER);

    JPanel dashboard = new JPanel(new BorderLayout());
    dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));

    this.spinner = new JSpinner(new SpinnerNumberModel(0, 0, m.getColCount() - 1, 1));
    spinner.addChangeListener(this);
    this.slider = new JSlider(0, m.getColCount() - 1, 0);
    slider.setPaintLabels(true);

    slider.setMajorTickSpacing(Math.max(50, 10 * Math.round(m.getColCount() / 100)));
    slider.setPaintTicks(true);
    this.slider.addChangeListener(this);

    FormLayout layout = new FormLayout("fill:0:g, max(20dlu; pref)", "top:pref");
    CellConstraints cc = new CellConstraints();
    DefaultFormBuilder fb = new DefaultFormBuilder(layout, Translation.INSTANCE.getBundle());

    fb.add(slider, cc.xy(1, 1));
    fb.add(spinner, cc.xy(2, 1));

    dashboard.add(fb.getPanel(), BorderLayout.CENTER);
    add(dashboard, BorderLayout.SOUTH);
    switchColumn(0);
}