List of usage examples for javax.swing JPanel setLayout
public void setLayout(LayoutManager mgr)
From source file:Main.java
public Main() { UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(1, 0, 0, 0)); UIManager.put("TabbedPane.contentAreaColor", new ColorUIResource(Color.GREEN)); UIManager.put("TabbedPane.focus", new ColorUIResource(Color.ORANGE)); UIManager.put("TabbedPane.selected", new ColorUIResource(Color.YELLOW)); UIManager.put("TabbedPane.darkShadow", new ColorUIResource(Color.DARK_GRAY)); UIManager.put("TabbedPane.borderHightlightColor", new ColorUIResource(Color.LIGHT_GRAY)); UIManager.put("TabbedPane.light", new ColorUIResource(Color.WHITE)); UIManager.put("TabbedPane.tabAreaBackground", new ColorUIResource(Color.CYAN)); UIManager.put("ToolTip.background", Color.WHITE); UIManager.put("ToolTip.border", new BorderUIResource(new LineBorder(Color.BLACK))); this.updateUI(); this.setBackground(Color.BLUE); JPanel testPanel = new JPanel(); testPanel.setLayout(new BorderLayout()); testPanel.add(new JLabel("Hello World"), BorderLayout.NORTH); testPanel.add(new JTextArea("Looks nice out there :)"), BorderLayout.CENTER); JPanel testPanel2 = new JPanel(); testPanel2.setLayout(new BorderLayout()); testPanel2.add(new JLabel("Good Bye World"), BorderLayout.NORTH); testPanel2.add(new JTextArea("OK"), BorderLayout.CENTER); this.addTab("Hello World", testPanel); this.addTab("World", testPanel2); }
From source file:JMFTest.java
JMFTest() { Player _player;/*from www . j a v a 2 s .c o m*/ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { _player.stop(); _player.deallocate(); _player.close(); System.exit(0); } }); setExtent(0, 0, 320, 260); JPanel panel = (JPanel) getContentPane(); panel.setLayout(new BorderLayout()); String mediaFile = "vfw://1"; try { MediaLocator mlr = new MediaLocator(mediaFile); _player = Manager.createRealizedPlayer(mlr); if (_player.getVisualComponent() != null) panel.add("Center", _player.getVisualComponent()); if (_player.getControlPanelComponent() != null) panel.add("South", _player.getControlPanelComponent()); } catch (Exception e) { System.err.println("Got exception " + e); } }
From source file:Main.java
private JPanel createPanel() { JPanel p = new JPanel(); p.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0;/*from w w w .j a va 2 s. co m*/ c.gridy = 0; c.anchor = GridBagConstraints.BASELINE_LEADING; p.add(new JLabel("Loan amount"), c); c.gridx++; p.add(new JTextField(15), c); c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; p.add(new JLabel("AUD"), c); c.gridx = 0; c.gridy++; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; p.add(new JLabel("Loan term"), c); c.gridx++; p.add(new JTextField(15), c); c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; p.add(new JLabel("Years"), c); return p; }
From source file:RTFView.java
public RTFView() { setTitle("RTF Text Application"); setSize(400, 240);/*from w w w.j a v a2 s . c o m*/ setBackground(Color.gray); getContentPane().setLayout(new BorderLayout()); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); getContentPane().add(topPanel, BorderLayout.CENTER); // Create an RTF editor window RTFEditorKit rtf = new RTFEditorKit(); JEditorPane editor = new JEditorPane(); editor.setEditorKit(rtf); editor.setBackground(Color.white); // This text could be big so add a scroll pane JScrollPane scroller = new JScrollPane(); scroller.getViewport().add(editor); topPanel.add(scroller, BorderLayout.CENTER); // Load an RTF file into the editor try { FileInputStream fi = new FileInputStream("test.rtf"); rtf.read(fi, editor.getDocument(), 0); } catch (FileNotFoundException e) { System.out.println("File not found"); } catch (IOException e) { System.out.println("I/O error"); } catch (BadLocationException e) { } }
From source file:WebBrowserBasedOnJEditorPane.java
public WebBrowserBasedOnJEditorPane() { setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel pnlURL = new JPanel(); pnlURL.setLayout(new BorderLayout()); pnlURL.add(new JLabel("URL: "), BorderLayout.WEST); pnlURL.add(txtURL, BorderLayout.CENTER); getContentPane().add(pnlURL, BorderLayout.NORTH); getContentPane().add(ep, BorderLayout.CENTER); getContentPane().add(lblStatus, BorderLayout.SOUTH); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { try { String url = ae.getActionCommand().toLowerCase(); if (url.startsWith("http://")) url = url.substring(7); ep.setPage("http://" + IDN.toASCII(url)); } catch (Exception e) { e.printStackTrace();// w w w.ja v a 2 s . c o m JOptionPane.showMessageDialog(WebBrowserBasedOnJEditorPane.this, "Browser problem: " + e.getMessage()); } } }; txtURL.addActionListener(al); setSize(300, 300); setVisible(true); }
From source file:CardLayoutDemo.java
public void addCardsToPane(Container pane) { JRadioButton[] rb = new JRadioButton[strings.length]; ButtonGroup group = new ButtonGroup(); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.PAGE_AXIS)); for (int i = 0; i < strings.length; i++) { rb[i] = new JRadioButton("Show component #" + (i + 1)); rb[i].setActionCommand(String.valueOf(i)); rb[i].addActionListener(this); group.add(rb[i]);/*from w w w . jav a 2s. com*/ buttons.add(rb[i]); } rb[0].setSelected(true); //Create the panel that contains the "cards". cards = new JPanel(new CardLayout()); for (int i = 0; i < strings.length; i++) { cards.add(createComponent(strings[i]), String.valueOf(i)); } pane.add(buttons, BorderLayout.NORTH); pane.add(cards, BorderLayout.CENTER); }
From source file:FramewithComponents.java
public FramewithComponents() { super("JLayeredPane Demo"); setSize(256, 256);/*from ww w. j a v a 2 s . c om*/ JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.setOpaque(false); JLabel label1 = new JLabel("Username:"); label1.setForeground(Color.white); content.add(label1); JTextField field = new JTextField(15); content.add(field); JLabel label2 = new JLabel("Password:"); label2.setForeground(Color.white); content.add(label2); JPasswordField fieldPass = new JPasswordField(15); content.add(fieldPass); getContentPane().setLayout(new FlowLayout()); getContentPane().add(content); ((JPanel) getContentPane()).setOpaque(false); ImageIcon earth = new ImageIcon("largeJava2sLogo.png"); JLabel backlabel = new JLabel(earth); getLayeredPane().add(backlabel, new Integer(Integer.MIN_VALUE)); backlabel.setBounds(0, 0, earth.getIconWidth(), earth.getIconHeight()); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(l); setVisible(true); }
From source file:Main.java
public Main(String title) { super(title); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container contentPane = this.getContentPane(); ButtonGroup group = new ButtonGroup(); small = new JRadioButton("small"); medium = new JRadioButton("medium"); large = new JRadioButton("large"); group.add(small);//from w w w.j a v a 2 s.c o m group.add(medium); group.add(large); button = new JButton("Click here."); button.setBounds(100, 50, 100, 50); JPanel center = new JPanel(); center.setLayout(null); center.add(button); contentPane.add(center, BorderLayout.CENTER); JPanel north = new JPanel(); north.add(small); north.add(medium); north.add(large); contentPane.add(north, BorderLayout.NORTH); ChangeSize listener = new ChangeSize(button); small.addItemListener(listener); medium.addItemListener(listener); large.addItemListener(listener); }
From source file:EditorPaneExample1.java
public EditorPaneExample1() { super("JEditorPane Example 1"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(4, 4)); JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, "West"); textField = new JTextField(32); panel.add(textField, "Center"); getContentPane().add(panel, "South"); // Change page based on text field textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String url = textField.getText(); try { // Try to display the page pane.setPage(url);/*from w w w. j a va 2 s .c o m*/ } catch (IOException e) { JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url }, "File Open Error", JOptionPane.ERROR_MESSAGE); } } }); }
From source file:ToolbarFrame2.java
public ToolbarFrame2() { setSize(450, 250);//from w w w . jav a 2 s.c om ActionListener printListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println(ae.getActionCommand()); } }; // JPanel works similarly to Panel, so we'll use it JPanel toolbar = new JPanel(); toolbar.setLayout(new FlowLayout(FlowLayout.LEFT)); cutButton = new JButton("Cut"); cutButton.addActionListener(printListener); toolbar.add(cutButton); copyButton = new JButton("Copy"); copyButton.addActionListener(printListener); toolbar.add(copyButton); pasteButton = new JButton("Paste"); pasteButton.addActionListener(printListener); toolbar.add(pasteButton); add(toolbar, BorderLayout.NORTH); // The new BorderLayout add JPanel lnfPanel = new JPanel(); macButton = new JButton("Mac"); macButton.addActionListener(printListener); lnfPanel.add(macButton); javaButton = new JButton("Metal"); javaButton.addActionListener(printListener); lnfPanel.add(javaButton); motifButton = new JButton("Motif"); motifButton.addActionListener(printListener); lnfPanel.add(motifButton); winButton = new JButton("Windows"); winButton.addActionListener(printListener); lnfPanel.add(winButton); add(lnfPanel, BorderLayout.SOUTH); }