List of usage examples for javax.swing JFrame getContentPane
public Container getContentPane()
contentPane
object for this frame. From source file:DoubleBufferWithBufferedImage.java
public static void main(String[] a) { JFrame f = new JFrame(); f.setSize(300, 300);//from w ww .ja v a 2 s. c o m f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new DoubleBufferWithBufferedImage()); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("SpringLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); // Set the content pane's layout as SpringLayout SpringLayout springLayout = new SpringLayout(); contentPane.setLayout(springLayout); // Add two JButtons to the content pane JButton b1 = new JButton("Button 1"); JButton b2 = new JButton("Little Bigger Button 2"); contentPane.add(b1);//from ww w. j a v a2s .com contentPane.add(b2); frame.pack(); frame.setVisible(true); }
From source file:OptionPaneSample.java
public static void main(String args[]) { JFrame f = new JFrame("JOptionPane Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); JButton button = new JButton("Ask"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); Object response = JOptionPane.showInputDialog(source, "Where do you want to go tomorrow?", "JOptionPane Sample", JOptionPane.QUESTION_MESSAGE, null, new String[] { "A", "B", "C", "D", "E" }, "E"); System.out.println("Response: " + response); }//from www . ja va2 s. co m }; button.addActionListener(actionListener); content.add(button, BorderLayout.CENTER); f.setSize(300, 200); f.setVisible(true); }
From source file:com.rest.samples.getImagePrintJPanel.java
public static void main(String[] args) { // TODO code application logic here String url = "https://api.adorable.io/avatars/eyes5"; try {//from w w w . jav a2 s . co m HttpClient hc = HttpClientBuilder.create().build(); HttpGet getMethod = new HttpGet(url); getMethod.addHeader("accept", "application/png"); HttpResponse res = hc.execute(getMethod); if (res.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode()); } InputStream is = res.getEntity().getContent(); Image image = ImageIO.read(is); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } catch (IOException ex) { Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Main.java
public static void main(String[] args) { String title = "GridBagLayout"; JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); for (int y = 0; y < 3; y++) { for (int x = 0; x < 4; x++) { gbc.gridx = x;/* w w w .j a v a 2 s .c o m*/ gbc.gridy = y; String text = "Button (" + x + ", " + y + ")"; contentPane.add(new JButton(text), gbc); } } frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Main mainPanel = new Main(); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack();/* w ww .j a v a 2 s .c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final int width = 512; final int height = 512; BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics g = img.getGraphics(); g.setColor(Color.black);//ww w .ja va 2 s .co m g.fillRect(0, 0, width, height); g.setColor(Color.white); final double A = 8; final double B = 0.5; final double N = 4; final double scale = 128; final double zoom = 50; final double step = 1 / scale; Point last = null; final Point origin = new Point(width / 2, height / 2); for (double t = 0; t <= 2 * Math.PI; t += step) { final double r = zoom * polarFunction(t, A, B, N); final int x = (int) Math.round(r * Math.cos(t)); final int y = (int) Math.round(r * Math.sin(t)); Point next = new Point(x, y); if (last != null) { g.drawLine(origin.x + last.x, origin.y + last.y, origin.x + next.x, origin.y + next.y); } last = next; } JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new JLabel(new ImageIcon(img))); frame.pack(); frame.setVisible(true); }
From source file:BoxLayoutYAXISTest.java
public static void main(String[] args) { JFrame f = new JFrame("Vertical BoxLayout-managed container"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); for (float align = 0.0f; align <= 1.0f; align += 0.25f) { JButton button = new JButton("X Alignment = " + align); button.setAlignmentX(align);/*ww w . ja va 2s. c o m*/ pane.add(button); } f.setSize(400, 300); f.setVisible(true); }
From source file:MainClass.java
public static void main(String argv[]) { java.net.URL u = null;/*from w ww . ja v a 2 s . c o m*/ try { u = new java.net.URL("http://www.java2s.com/"); } catch (java.net.MalformedURLException ignored) { } JFormattedTextField ftf1 = new JFormattedTextField(u); JFormattedTextField ftf2 = new JFormattedTextField(u); ftf2.setInputVerifier(new InputVerifier() { public boolean verify(JComponent input) { if (!(input instanceof JFormattedTextField)) return true; return ((JFormattedTextField) input).isEditValid(); } }); JPanel p = new JPanel(new GridLayout(0, 2, 3, 8)); p.add(new JLabel("plain JFormattedTextField:")); p.add(ftf1); p.add(new JLabel("FTF with InputVerifier:")); p.add(ftf2); p.add(new JLabel("plain JTextField:")); p.add(new JTextField(u.toString())); JFrame f = new JFrame("MainClass"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JLabel("Try to delete the colon in each field."), "North"); f.getContentPane().add(p, "Center"); f.pack(); f.setVisible(true); }
From source file:FileTreeDemo.java
public static void main(String[] args) { // Figure out where in the filesystem to start displaying File root;/*from w w w. j av a 2 s . co m*/ if (args.length > 0) root = new File(args[0]); else root = new File(System.getProperty("user.home")); // Create a TreeModel object to represent our tree of files FileTreeModel model = new FileTreeModel(root); // Create a JTree and tell it to display our model JTree tree = new JTree(); tree.setModel(model); // The JTree can get big, so allow it to scroll. JScrollPane scrollpane = new JScrollPane(tree); // Display it all in a window and make the window appear JFrame frame = new JFrame("FileTreeDemo"); frame.getContentPane().add(scrollpane, "Center"); frame.setSize(400, 600); frame.setVisible(true); }