List of usage examples for javax.swing JPanel setBorder
@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.") public void setBorder(Border border)
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Table Title", TitledBorder.CENTER, TitledBorder.TOP)); JTable table = new JTable(3, 3); panel.add(new JScrollPane(table)); frame.add(panel);//from ww w .j a va2 s .c o m frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createLineBorder(Color.RED)); BoxLayout mgr = new BoxLayout(panel, BoxLayout.Y_AXIS); panel.setLayout(mgr);/* w ww .j a va 2 s .c o m*/ for (int i = 0; i < 5; i++) { JButton button = new JButton("Remove Hello World " + (i + 1)); button.setAlignmentX(Component.CENTER_ALIGNMENT); button.addActionListener(e -> { panel.remove(button); panel.revalidate(); panel.repaint(); }); panel.add(button); } frame.add(panel); frame.pack(); frame.setVisible(true); }
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);/*from www . j a v a2 s .co m*/ panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JOptionPane.showMessageDialog(null, panel); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout()); gui.setBorder(new TitledBorder("Border Layout")); JPanel labels = new JPanel(); labels.setBorder(new TitledBorder("Flow Layout")); labels.add(new JLabel("Label 1")); labels.add(new JLabel("Label 2")); gui.add(labels, BorderLayout.NORTH); gui.add(new JButton("Button"), BorderLayout.SOUTH); JOptionPane.showMessageDialog(null, gui); }
From source file:Main.java
public static void main(String[] args) { JPanel ui = new JPanel(new BorderLayout(20, 20)); ui.setBorder(new LineBorder(Color.RED, 1)); JTextField fileName = new JTextField(); ui.add(fileName, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(new GridLayout(1, 0, 10, 30)); ui.add(buttonPanel, BorderLayout.CENTER); JButton creater = new JButton("Create File"); buttonPanel.add(creater);/*from ww w .j a va 2 s . c o m*/ JButton deleter = new JButton("Delete File"); buttonPanel.add(deleter); JOptionPane.showMessageDialog(null, ui); }
From source file:Main.java
public static void main(String[] args) { SpringLayout layout = new SpringLayout(); JPanel p = new JPanel(layout); p.setBorder(BorderFactory.createLineBorder(Color.GREEN, 10)); JLabel l1 = new JLabel("label: width=90%", SwingConstants.CENTER); l1.setBorder(BorderFactory.createLineBorder(Color.RED, 1)); JButton l2 = new JButton("button: width=50%"); Spring panelw = layout.getConstraint(WIDTH, p); SpringLayout.Constraints c1 = layout.getConstraints(l1); c1.setX(Spring.constant(0));//from ww w.j a v a 2s .c om c1.setY(Spring.constant(20)); c1.setWidth(Spring.scale(panelw, 0.9f)); p.add(l1); SpringLayout.Constraints c2 = layout.getConstraints(l2); c2.setWidth(Spring.scale(panelw, 0.5f)); layout.putConstraint(SOUTH, l2, -20, SOUTH, p); layout.putConstraint(EAST, l2, -20, EAST, p); p.add(l2); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(p); f.setSize(320, 240); f.setVisible(true); }
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 www . j ava 2s .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 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);/*ww w. ja v a2s. c o m*/ f.pack(); f.setLocationByPlatform(true); 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 . ja v a2s . 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); }
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)); }/*from w w w . j a v a 2s . c o m*/ 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); }