List of usage examples for javax.swing JPanel add
public Component add(Component comp)
From source file:BoxSample.java
public static void main(String args[]) { JButton button;//from w w w . j a va2 s . c o m Vector buttons = new Vector(); Dimension dim; JFrame frame = new JFrame("Box Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS)); JPanel topLeft = new JPanel(); topLeft.setLayout(new BoxLayout(topLeft, BoxLayout.X_AXIS)); topLeft.add(button = new JButton("One")); buttons.add(button); changeBoth(button); topLeft.add(button = new JButton("Two")); buttons.add(button); changeBoth(button); changeWidth(topLeft); JPanel bottomLeft = new JPanel(); bottomLeft.setLayout(new BoxLayout(bottomLeft, BoxLayout.X_AXIS)); bottomLeft.add(button = new JButton("Six")); buttons.add(button); changeBoth(button); bottomLeft.add(button = new JButton("Seven")); buttons.add(button); changeBoth(button); changeWidth(bottomLeft); JPanel left = new JPanel(); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); left.add(topLeft); left.add(button = new JButton("Four")); buttons.add(button); changeBoth(button); left.add(bottomLeft); changeBoth(left); JPanel right = new JPanel(); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); right.add(button = new JButton("Three")); buttons.add(button); changeWidth(button); right.add(button = new JButton("Five")); buttons.add(button); changeBoth(button); changeBoth(right); contentPane.add(left); contentPane.add(right); tweak(buttons); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { String title = (args.length == 0 ? "CheckBox Sample" : args[0]); JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Pizza Toppings"); panel.setBorder(border);//from w w w . j av a 2 s . co m JCheckBox check = new JCheckBox("Anchovies"); panel.add(check); check = new JCheckBox("Garlic"); panel.add(check); check = new JCheckBox("Onions"); panel.add(check); check = new JCheckBox("Pepperoni"); panel.add(check); check = new JCheckBox("Spinach"); panel.add(check); JButton button = new JButton("Submit"); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:DragImage.java
public static void main(String args[]) { JFrame frame = new JFrame("Clip Image"); Container contentPane = frame.getContentPane(); final Clipboard clipboard = frame.getToolkit().getSystemClipboard(); Icon icon = new ImageIcon("jaeger.jpg"); final JLabel label = new JLabel(icon); label.setTransferHandler(new ImageSelection()); MouseListener mouseListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent comp = (JComponent) e.getSource(); TransferHandler handler = comp.getTransferHandler(); handler.exportAsDrag(comp, e, TransferHandler.COPY); }//from ww w . j av a 2s . c o m }; label.addMouseListener(mouseListener); JScrollPane pane = new JScrollPane(label); contentPane.add(pane, BorderLayout.CENTER); JButton copy = new JButton("Copy"); copy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { TransferHandler handler = label.getTransferHandler(); handler.exportToClipboard(label, clipboard, TransferHandler.COPY); } }); JButton clear = new JButton("Clear"); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { label.setIcon(null); } }); clear.setTransferHandler(new TransferHandler("text")); mouseListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent comp = (JComponent) e.getSource(); TransferHandler handler = comp.getTransferHandler(); handler.exportAsDrag(comp, e, TransferHandler.COPY); } }; clear.addMouseListener(mouseListener); JButton paste = new JButton("Paste"); paste.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Transferable clipData = clipboard.getContents(clipboard); if (clipData != null) { if (clipData.isDataFlavorSupported(DataFlavor.imageFlavor)) { TransferHandler handler = label.getTransferHandler(); handler.importData(label, clipData); } } } }); JPanel p = new JPanel(); p.add(copy); p.add(clear); p.add(paste); contentPane.add(p, BorderLayout.SOUTH); JTextField tf = new JTextField(); tf.setDragEnabled(true); contentPane.add(tf, BorderLayout.NORTH); frame.setSize(300, 300); frame.show(); }
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;//from w w w .j av a2 s .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:ColorSink.java
/** This is a simple test program for ColorSource and ColorSink */ public static void main(String[] args) { // Create a window JFrame f = new JFrame("ColorSourceTest"); f.getContentPane().setLayout(new BorderLayout()); // Add some ColorSources JPanel panel = new JPanel(); f.getContentPane().add(panel, BorderLayout.NORTH); panel.add(new ColorSource(Color.yellow)); panel.add(new ColorSource(Color.pink)); panel.add(new ColorSource(Color.white)); panel.add(new ColorSource(Color.gray)); // Add a ColorSink ColorSink sink = new ColorSink(); f.getContentPane().add(sink, BorderLayout.CENTER); // Pop it all up f.setSize(400, 300);/*from ww w .j a v a 2 s . com*/ f.show(); }
From source file:MyButtonUI.java
public static void main(String argv[]) { JFrame f = new JFrame(); f.setSize(400, 300);/*from w w w.j a v a2 s . c o m*/ f.getContentPane().setLayout(new FlowLayout()); JPanel p = new JPanel(); JButton bt1 = new JButton("Click Me"); bt1.setUI(new MyButtonUI()); p.add(bt1); f.getContentPane().add(p); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel controlPane = new JPanel(); JPanel buttonPane = new JPanel(); controlPane.setLayout(new BoxLayout(controlPane, BoxLayout.PAGE_AXIS)); controlPane.setPreferredSize(new Dimension(200, 200)); controlPane.add(new JScrollPane(new JTextArea())); buttonPane.setLayout(new FlowLayout(FlowLayout.LEFT)); buttonPane.setPreferredSize(new Dimension(100, 40)); buttonPane.add(new JButton("Button1")); buttonPane.add(new JButton("Button2")); frame.add(controlPane, BorderLayout.NORTH); frame.add(buttonPane, BorderLayout.SOUTH); frame.pack();//from w ww . j a v a 2s .c om frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setTitle("Example2"); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p1.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 1")); for (int i = 0; i < NB1; i++) p1.add(new JButton("Button " + i)); JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p2.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 2")); for (int i = NB1; i < NB2; i++) p2.add(new JButton("Button " + i)); JPanel p3 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p3.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 3")); for (int i = NB2; i < NB3; i++) p3.add(new JButton("Button " + i)); JPanel global = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; // added gbc.weightx = 1.0f; // added gbc.gridy = 0;//from w ww .ja v a 2 s . c om global.add(p1, gbc); gbc.gridy++; global.add(p2, gbc); gbc.gridy++; global.add(p3, gbc); f.add(global); f.pack(); f.setVisible(true); }
From source file:ArrowIcon.java
public static void main(String args[]) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.add(panel);/* w w w . j a v a2s. co m*/ panel.add(new JLabel("north", new ArrowIcon(ArrowIcon.NORTH), JLabel.CENTER)); panel.add(new JLabel("west", new ArrowIcon(ArrowIcon.WEST), JLabel.CENTER)); panel.add(new JLabel("south", new ArrowIcon(ArrowIcon.SOUTH), JLabel.CENTER)); panel.add(new JLabel("east", new ArrowIcon(ArrowIcon.EAST), JLabel.CENTER)); panel.add(new JLabel("east-20", new ArrowIcon(ArrowIcon.EAST, 20, Color.blue), JLabel.CENTER)); frame.pack(); frame.setVisible(true); }
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 w w w .j a v a 2 s . c o m frame.pack(); frame.setVisible(true); }