List of usage examples for javax.swing JPanel add
public Component add(String name, Component comp)
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LINE_ENDS); frame.add(outerPanel);// w w w .j av a 2s. c o m frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);//from w w w . ja va 2 s. co m frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Sorting JTable"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MyTableModel model = new MyTableModel(); JTable table = new JTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);/*from w w w. j a v a2 s.co m*/ JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Filter"); panel.add(label, BorderLayout.WEST); final JTextField filterText = new JTextField("Y"); panel.add(filterText, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); JButton button = new JButton("Filter"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = filterText.getText(); try { sorter.setRowFilter(RowFilter.regexFilter(text)); } catch (PatternSyntaxException pse) { System.err.println("Bad regex pattern"); } } }); frame.add(button, BorderLayout.SOUTH); frame.setSize(300, 250); frame.setVisible(true); }
From source file:RegexTable.java
public static void main(String args[]) { JFrame frame = new JFrame("Regexing JTable"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Object rows[][] = { { "A", "About", 44.36 }, { "B", "Boy", 44.84 }, { "C", "Cat", 463.63 }, { "D", "Day", 27.14 }, { "E", "Eat", 44.57 }, { "F", "Fail", 23.15 }, { "G", "Good", 4.40 }, { "H", "Hot", 24.96 }, { "I", "Ivey", 5.45 }, { "J", "Jack", 49.54 }, { "K", "Kids", 280.00 } }; String columns[] = { "Symbol", "Name", "Price" }; TableModel model = new DefaultTableModel(rows, columns) { public Class getColumnClass(int column) { Class returnValue;/*from w w w . j av a 2s .c o m*/ if ((column >= 0) && (column < getColumnCount())) { returnValue = getValueAt(0, column).getClass(); } else { returnValue = Object.class; } return returnValue; } }; final JTable table = new JTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Filter"); panel.add(label, BorderLayout.WEST); final JTextField filterText = new JTextField("A"); panel.add(filterText, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); JButton button = new JButton("Filter"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = filterText.getText(); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter(text)); } } }); frame.add(button, BorderLayout.SOUTH); frame.setSize(300, 250); frame.setVisible(true); }
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 w w w . j a va 2 s.c om*/ JButton deleter = new JButton("Delete File"); buttonPanel.add(deleter); JOptionPane.showMessageDialog(null, ui); }
From source file:Main.java
public static void main(String[] args) { ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("js"); String[] ops = { "+", "-", "*", "/" }; JPanel gui = new JPanel(new BorderLayout(2, 2)); JPanel labels = new JPanel(new GridLayout(0, 1)); gui.add(labels, BorderLayout.WEST); labels.add(new JLabel("a")); labels.add(new JLabel("operand")); labels.add(new JLabel("b")); labels.add(new JLabel("=")); JPanel controls = new JPanel(new GridLayout(0, 1)); gui.add(controls, BorderLayout.CENTER); JTextField a = new JTextField(10); controls.add(a);/*w w w . j a v a 2s . co m*/ JComboBox operand = new JComboBox(ops); controls.add(operand); JTextField b = new JTextField(10); controls.add(b); JTextField output = new JTextField(10); controls.add(output); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { String expression = a.getText() + operand.getSelectedItem() + b.getText(); try { Object result = engine.eval(expression); if (result == null) { output.setText("Output was 'null'"); } else { output.setText(result.toString()); } } catch (ScriptException se) { output.setText(se.getMessage()); } } }; operand.addActionListener(al); a.addActionListener(al); b.addActionListener(al); JOptionPane.showMessageDialog(null, gui); }
From source file:Main.java
public static void main(String[] args) { JPanel topPanel = new JPanel(); topPanel.setPreferredSize(new Dimension(200, 200)); topPanel.setBackground(Color.WHITE); JTextArea chatArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(chatArea); JPanel mainPanel = new JPanel(new BorderLayout(5, 5)); mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); mainPanel.add(topPanel, BorderLayout.CENTER); mainPanel.add(scrollPane, BorderLayout.SOUTH); chatArea.getDocument().addDocumentListener(new DocumentListener() { @Override/*from w w w. j a v a 2 s. c om*/ public void insertUpdate(DocumentEvent e) { updateLineCount(); } @Override public void removeUpdate(DocumentEvent e) { updateLineCount(); } @Override public void changedUpdate(DocumentEvent e) { updateLineCount(); } private void updateLineCount() { int lineCount = chatArea.getLineCount(); if (lineCount <= 4) { chatArea.setRows(lineCount); mainPanel.revalidate(); } } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(mainPanel); f.pack(); f.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);/*from ww w .ja v a 2 s . co m*/ f.pack(); f.setLocationByPlatform(true); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout()); gui.setPreferredSize(new Dimension(400, 100)); JDesktopPane dtp = new JDesktopPane(); gui.add(dtp, BorderLayout.CENTER); JButton newFrame = new JButton("Add Frame"); ActionListener listener = new ActionListener() { private int disp = 10; @Override// ww w. j av a 2s . c o m public void actionPerformed(ActionEvent e) { JInternalFrame jif = new JInternalFrame(); dtp.add(jif); jif.setLocation(disp, disp); jif.setSize(100, 100); disp += 10; jif.setVisible(true); } }; newFrame.addActionListener(listener); gui.add(newFrame, BorderLayout.PAGE_START); JFrame f = new JFrame(); f.add(gui); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setLocationByPlatform(true); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); String[] values = new String[] { "One", "Two", "Three" }; JComboBox<String> comboBox = new JComboBox<>(values); panel.add(comboBox, BorderLayout.NORTH); JTextArea textArea = new JTextArea(2, 2); panel.add(textArea, BorderLayout.CENTER); JButton button = new JButton("Action"); button.addActionListener(new ActionListener() { @Override/*ww w.j a v a2s .co m*/ public void actionPerformed(ActionEvent e) { textArea.setText((String) comboBox.getSelectedItem()); comboBox.setSelectedIndex(0); } }); panel.add(button, BorderLayout.SOUTH); JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }