List of usage examples for javax.swing JPanel JPanel
public JPanel()
JPanel
with a double buffer and a flow layout. From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); JTextPane textPane = new JTextPane(); JButton button = new JButton("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(new BorderLayout()); panel.setPreferredSize(new Dimension(200, 200)); panel.add(textPane, BorderLayout.CENTER); panel.add(button, BorderLayout.SOUTH); textPane.addStyle("myStyle", null); button.addActionListener(e -> {/*from w ww . j a v a 2 s. c om*/ StyledDocument doc = textPane.getStyledDocument(); int start = textPane.getSelectionStart(); int end = textPane.getSelectionEnd(); if (start == end) { return; } if (start > end) { int life = start; start = end; end = life; } Style style = textPane.getStyle("myStyle"); if (StyleConstants.isBold(style)) { StyleConstants.setBold(style, false); } else { StyleConstants.setBold(style, true); } doc.setCharacterAttributes(start, end - start, style, false); }); frame.add(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] items = { "A", "B", "C" }; JComboBox<String> comboBox1 = new MyComboBox1<>(items); JPanel p = new JPanel(); p.add(comboBox1);/*ww w . j a v a 2 s. com*/ JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.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[]) { String[] columnNames = { "Date", "Field", "Home Team", "Visitor Team", "Score" }; JFrame guiFrame = new JFrame(); guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); guiFrame.setSize(500, 500);//from w w w . ja va 2 s . c o m JPanel panel = new JPanel(); panel.setSize(450, 450); JLabel titleLabel = new JLabel("OK"); String[][] data = new String[0][0]; JTable scheduleTable = new JTable(data, columnNames); JScrollPane scrollPane = new JScrollPane(scheduleTable); panel.add(scrollPane); panel.add(titleLabel); guiFrame.add(panel); guiFrame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] ITEMS1 = { "one", "two", "three", "four", "five" }; String[] ITEMS2 = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" }; JPanel northPanel = new JPanel(); northPanel.add(new JCheckBox("Reminder")); northPanel.add(new JComboBox(ITEMS1)); northPanel.add(new JComboBox(ITEMS2)); JPanel p = new JPanel(new BorderLayout()); p.add(northPanel, BorderLayout.NORTH); p.add(new JScrollPane(new JTextArea(8, 30)), BorderLayout.CENTER); JFrame frame = new JFrame(); frame.getContentPane().add(p);// www. j a v a 2 s . co m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 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); frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS)); JPanel a = new JPanel(); a.setAlignmentX(Component.CENTER_ALIGNMENT); a.setPreferredSize(new Dimension(100, 100)); a.setMaximumSize(new Dimension(100, 100)); // set max = pref a.setBorder(BorderFactory.createTitledBorder("aa")); JPanel b = new JPanel(); b.setAlignmentX(Component.CENTER_ALIGNMENT); b.setPreferredSize(new Dimension(50, 50)); b.setMaximumSize(new Dimension(50, 50)); // set max = pref b.setBorder(BorderFactory.createTitledBorder("bb")); frame.getContentPane().add(a);// w w w . ja v a 2s.c o m frame.getContentPane().add(b); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS); container.setLayout(layout);/*from ww w .j a va2 s. com*/ for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(Component.BOTTOM_ALIGNMENT); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);// w w w.j ava 2 s . c o m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(Component.LEFT_ALIGNMENT); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS); container.setLayout(layout);// w w w.j av a2s . c o m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(Component.TOP_ALIGNMENT); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);//from ww w .j a v a 2 s . c o m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(Component.CENTER_ALIGNMENT); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);/* ww w.jav a2 s. c om*/ for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(Component.RIGHT_ALIGNMENT); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }