List of usage examples for javax.swing JPanel add
public Component add(Component comp)
From source file:Main.java
public static void main(String[] args) { int ROW_HEIGHT = 40; String[] TABLE_COLUMNS = { "Foo", "Bar" }; DefaultTableModel tableModel = new DefaultTableModel(TABLE_COLUMNS, 2); JTable table = new JTable(tableModel); table.setRowHeight(ROW_HEIGHT);//from w w w . ja v a 2 s. c om JScrollPane scrollpane = new JScrollPane(table); JButton addRowBtn = new JButton(new AbstractAction("Add Row") { @Override public void actionPerformed(ActionEvent arg0) { tableModel.addRow(new String[] { "", "" }); } }); JPanel btnPanel = new JPanel(); btnPanel.add(addRowBtn); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(scrollpane, BorderLayout.CENTER); f.getContentPane().add(btnPanel, BorderLayout.PAGE_END); f.pack(); f.setLocationByPlatform(true); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Integer[] numbers = { 1, 2, 3 }; String[] names = { "A", "B", "C" }; JComboBox numberCombo = new JComboBox(numbers); JComboBox nameCombo = new JComboBox(names); JPanel p = new JPanel(new GridLayout(0, 1, 3, 3)); p.add(numberCombo); p.add(nameCombo);//from w ww . jav a 2 s.c o m JOptionPane.showMessageDialog(null, p); Integer chosenNumber = (Integer) numberCombo.getSelectedItem(); System.out.println("Chosen Number: " + chosenNumber); String chosenName = (String) nameCombo.getSelectedItem(); System.out.println("Chosen Name: " + chosenName); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel buttonPanel = new JPanel(new FlowLayout(), true); buttonPanel.add(new JButton("A")); frame.add(buttonPanel);//from w w w. j a va2s .c o m frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[][] data = { { "Data", "Data" } }; String[] col = { "Col", "Col" }; final DefaultTableModel model = new DefaultTableModel(data, col); JTable table = new JTable(model); JButton addRow = new JButton("Add Empty Row"); addRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.addRow(new Object[] {}); }// www. java 2 s. co m }); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JScrollPane(table)); panel.add(addRow, BorderLayout.SOUTH); JOptionPane.showMessageDialog(null, panel); }
From source file:Main.java
public static void main(String[] args) throws Exception { String mapUrlPath = "http://www.java2s.com/style/download.png"; URL mapUrl = new URL(mapUrlPath); BufferedImage mapImage = ImageIO.read(mapUrl); Image newMapImage = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(mapImage.getSource(), new GrayToColorFilter(Color.red))); ImageIcon mapIcon = new ImageIcon(mapImage); ImageIcon newMapIcon = new ImageIcon(newMapImage); JPanel imagePanel = new JPanel(); imagePanel.add(new JLabel(mapIcon)); imagePanel.add(new JLabel(newMapIcon)); JOptionPane.showMessageDialog(null, imagePanel); }
From source file:Main.java
public static void main(String[] args) { int specificX = 40; int specificY = 20; JPanel gui = new JPanel(new BorderLayout()); JTextField tf = new JTextField(10); JPanel borderPanel = new JPanel(new GridLayout()); borderPanel.add(tf); borderPanel.setBorder(new EmptyBorder(specificX, specificY, specificX, specificY)); borderPanel.setBackground(Color.GREEN); gui.add(borderPanel);/* w ww. j av a 2s. c om*/ JOptionPane.showMessageDialog(null, gui); }
From source file:Main.java
public static void main(String[] args) { JPanel bottomPanel = new JPanel(); bottomPanel.add(new JButton("Bottom Button")); bottomPanel.setBorder(BorderFactory.createTitledBorder("Bottom Panel")); JPanel centerPanel = new JPanel(); centerPanel.setBorder(BorderFactory.createTitledBorder("Center Panel")); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(centerPanel, BorderLayout.CENTER); mainPanel.add(bottomPanel, BorderLayout.PAGE_END); int eb = 25;/*from w w w . j ava2s . c om*/ mainPanel.setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb)); mainPanel.setPreferredSize(new Dimension(500, 400)); JFrame frame = new JFrame("Main"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:DefaultFormatterFactoryDemo.java
public static void main(String args[]) { JFrame frame = new JFrame("Mask Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Date"); DateFormat displayFormat = new SimpleDateFormat("yyyy--MMMM--dd"); DateFormatter displayFormatter = new DateFormatter(displayFormat); DateFormat editFormat = new SimpleDateFormat("MM/dd/yy"); DateFormatter editFormatter = new DateFormatter(editFormat); DateFormat nullFormat = new SimpleDateFormat("'null'"); DateFormatter nullFormatter = new DateFormatter(nullFormat); DefaultFormatterFactory factory = new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter, nullFormatter); JFormattedTextField input = new JFormattedTextField(factory); input.setColumns(30);//from w w w. j ava 2 s .c om JPanel panel = new JPanel(); panel.add(label); panel.add(input); frame.add(panel, "North"); frame.add(new JTextField(), "Center"); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton component = new JButton(); JPanel panel = new JPanel(null); component.setBounds(1, 1, 100, 100); panel.add(component); }
From source file:Main.java
public static void main(String[] args) { JTabbedPane tab = new JTabbedPane(); tab.addTab("New tab1", new JLabel("1")); tab.addTab("New Tab2", new JLabel("2")); JPanel p = new JPanel(new BorderLayout()); p.add(new JLayer<JComponent>(tab, new TopRightCornerLabelLayerUI())); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(p);/*from w ww . j a va 2s . co m*/ f.setSize(320, 240); f.setVisible(true); }