List of usage examples for javax.swing JPanel JPanel
public JPanel()
JPanel
with a double buffer and a flow layout. From source file:Main.java
public static void main(String[] args) { JComboBox combo = new JComboBox(); combo.setEditable(true);/* www . j av a2 s.c om*/ for (int i = 0; i < 10; i++) { combo.addItem(i); } JLabel tip = new JLabel(); tip.setText("Outside combobox"); JPanel panel = new JPanel(); panel.add(combo); panel.add(tip); panel.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { tip.setText("Outside combobox"); } @Override public void mouseExited(MouseEvent e) { Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); tip.setText(c != null && SwingUtilities.isDescendingFrom(c, combo) ? "Inside combo box" : "Outside combobox"); } }); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Cycle Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 3)); for (int i = 0; i < 3; i++) { JButton button = new JButton("" + i); frame.add(button);/* ww w. j av a 2 s. com*/ } JPanel panel = new JPanel(); panel.setFocusCycleRoot(true); panel.setFocusTraversalPolicyProvider(true); panel.setLayout(new GridLayout(1, 3)); for (int i = 0; i < 3; i++) { JButton button = new JButton("" + (i + 3)); panel.add(button); } frame.add(panel); for (int i = 0; i < 3; i++) { JButton button = new JButton("" + (i + 6)); frame.add(button); } frame.setSize(300, 200); frame.setVisible(true); }
From source file:JDK6TextComponentDemo.java
public static void main(String[] args) throws Exception { final JTextArea textArea = new JTextArea(); textArea.setText("text"); JScrollPane jScrollPane = new JScrollPane(textArea); final MessageFormat header = new MessageFormat("My Header"); final MessageFormat footer = new MessageFormat("My Footer"); JPanel contentPane = new JPanel(); contentPane.setLayout(new BorderLayout()); contentPane.add(jScrollPane, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setTitle("Text-component Printing Demo"); frame.setSize(400, 200);/*ww w. j av a 2 s . co m*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(contentPane); frame.setVisible(true); textArea.print(header, footer, true, null, null, true); }
From source file:Main.java
public static void main(String[] args) { Runnable r = new Runnable() { @Override/*from ww w .jav a2 s .co m*/ public void run() { JPanel gui = new JPanel(); final AnimatedImage[] tiles = new AnimatedImage[2]; for (int ii = 0; ii < tiles.length; ii++) { tiles[ii] = new AnimatedImage(); gui.add(new JLabel(new ImageIcon(tiles[ii]))); } ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < tiles.length; i++) { tiles[i].paintImage(); gui.repaint(); } } }; Timer timer = new Timer(50, listener); timer.start(); JOptionPane.showMessageDialog(null, gui); timer.stop(); } }; SwingUtilities.invokeLater(r); }
From source file:ActiveSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Active Example"); UIManager.put(LABEL_FACTORY, new ActiveLabel()); final JPanel panel = new JPanel(); JButton button = new JButton("Get"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JLabel label = (JLabel) UIManager.get(LABEL_FACTORY); panel.add(label);//from w w w .j a va 2 s. com panel.revalidate(); } }; button.addActionListener(actionListener); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(200, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String... args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel contentPane = new JPanel(); contentPane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); JTextField tfield1 = new JTextField(10); JTextField tfield2 = new JTextField(10); FocusListener tfieldListener = new FocusListener() { @Override/*from w w w . jav a 2s .c o m*/ public void focusGained(FocusEvent fe) { } @Override public void focusLost(FocusEvent fe) { String num1 = tfield1.getText().trim(); String num2 = tfield2.getText().trim(); if (num1 == null || num1.equals("")) num1 = "0"; if (num2 == null || num2.equals("")) num2 = "0"; System.out.println(Integer.toString(Integer.parseInt(num1) + Integer.parseInt(num2))); } }; tfield1.addFocusListener(tfieldListener); tfield2.addFocusListener(tfieldListener); ((AbstractDocument) tfield1.getDocument()).setDocumentFilter(new MyDocumentFilter()); ((AbstractDocument) tfield2.getDocument()).setDocumentFilter(new MyDocumentFilter()); contentPane.add(tfield1); contentPane.add(tfield2); frame.setContentPane(contentPane); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); p.setOpaque(true);/*from w ww .ja v a 2s. c om*/ p.setLayout(new FlowLayout()); p.add(good); f.add(p, BorderLayout.CENTER); f.add(resultLabel, BorderLayout.SOUTH); good.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { resultLabel.setText("Working . . ."); good.setEnabled(false); Thread worker = new Thread() { public void run() { try { Thread.sleep(5000); } catch (InterruptedException ex) { } SwingUtilities.invokeLater(new Runnable() { public void run() { resultLabel.setText("Ready"); good.setEnabled(true); } }); } }; worker.start(); // So we don't hold up the dispatch thread. } }); f.setSize(300, 100); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.pack();/*from w w w. j av a 2 s . c om*/ Container contentPane = frame.getContentPane(); contentPane.setLayout(null); for (int i = 0; i < 4; i++) { JPanel panel = new JPanel(); panel.setBounds((i * 75) + 475, 25, 75, 100); System.out.println(panel.getBounds()); contentPane.add(panel); panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 3)); } System.out.println(getComponentAt(contentPane, new Point(475, 25))); System.out.println(getComponentAt(contentPane, new Point(100, 25))); frame.setVisible(true); }
From source file:GlassExample.java
/** Construct a Splash screen with the given image */ public static void main(String[] args) { JFrame f = new JFrame("GlassPane"); final JPanel p1 = new JPanel(); p1.add(new JLabel("GlassPane Example")); JButton show = new JButton("Show"); p1.add(show);//from w w w.j av a2 s .co m p1.add(new JButton("No-op")); f.getContentPane().add(p1); final JPanel glass = (JPanel) f.getGlassPane(); glass.setVisible(true); glass.setLayout(new GridBagLayout()); JButton glassButton = new JButton("Hide"); glass.add(glassButton); f.setSize(150, 80); f.setVisible(true); boolean debug = false; if (debug) { System.out.println("Button is " + glassButton); System.out.println("GlassPane is " + glass); } // Add actions to the buttons... // show button (re-)shows the glass pane. show.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { glass.setVisible(true); p1.repaint(); } }); // hide button hides the Glass Pane to show what's under. glassButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { glass.setVisible(false); p1.repaint(); } }); }
From source file:MainClass.java
public static void main(String args[]) { final String LABEL_FACTORY = "LabelFactory"; JFrame frame = new JFrame("Active Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); UIManager.put(LABEL_FACTORY, new ActiveLabel()); final JPanel panel = new JPanel(); JButton button = new JButton("Get"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JLabel label = (JLabel) UIManager.get(LABEL_FACTORY); panel.add(label);// w w w .jav a 2 s . com panel.revalidate(); } }; button.addActionListener(actionListener); frame.add(panel, BorderLayout.CENTER); frame.add(button, BorderLayout.SOUTH); frame.setSize(200, 200); frame.setVisible(true); }