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) { final int columnCount = 10; final int side = 25; final int[][] grid = new int[50][columnCount]; JPanel panel = new JPanel() { public void paintComponent(Graphics g) { Font font = new Font("WingDings", Font.PLAIN, 14); g.setFont(font);/*from w w w. j a va 2 s . c o m*/ int off = 0; for (int i = 0; i < 256 * 256; i++) { if (font.canDisplay((char) i) == false) { continue; } off++; grid[off / columnCount][off % columnCount] = i; int x = off % columnCount * side; int y = (off / columnCount) * side + side; g.drawString(Character.toString((char) i), x, y); } } }; JFrame frame = new JFrame(); panel.setSize(300, 300); frame.getContentPane().add(panel); frame.setSize(300, 300); 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(); Container c = frame.getContentPane(); panel.setSize(100, 100);//from w w w . j a v a 2 s .c o m panel.setLayout(new GridLayout(1000, 1)); for (int i = 0; i < 1000; i++) panel.add(new JLabel("JLabel " + i)); JScrollPane jsp = new JScrollPane(panel); c.add(jsp); frame.setSize(100, 100); 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 panel = new JPanel() { @Override/*from w ww. j a v a 2s. c om*/ protected void paintComponent(Graphics g) { super.paintComponent(g); int y = 0; for (int size = 4; size <= 24; size += 2) { g.setFont(new Font("Arial", Font.BOLD, size)); g.drawString("Name", 0, y); int heightOfFont = g.getFontMetrics().getHeight(); y += heightOfFont; } } @Override public Dimension getPreferredSize() { return new Dimension(300, 300); } }; frame.add(panel); frame.setLocationByPlatform(true); frame.setVisible(true); frame.pack(); }
From source file:ImageTest.java
public static void main(String[] args) { JPanel panel = new JPanel(); final ImageButton button = new ImageButton("button.png"); button.setPressedIcon(new ImageIcon("down.png")); button.setRolloverIcon(new ImageIcon("over.png")); button.setSelectedIcon(new ImageIcon("sel.png")); button.setRolloverSelectedIcon(new ImageIcon("sel-over.png")); button.setDisabledIcon(new ImageIcon("disabled.png")); button.setDisabledSelectedIcon(new ImageIcon("disabled-selected.png")); button.setLocation(60, 74);//from w w w . j a v a 2s.c o m button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { button.setSelected(!button.isSelected()); System.out.println("selecting"); } }); // button.setSelected(true); // button.setDisabled(false); panel.add(button); JFrame frame = new JFrame(); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame("This is BOX LAYOUT"); JPanel panel1 = new JPanel(); panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS)); panel1.setBackground(Color.yellow); JPanel panel2 = new JPanel(); panel2.setLayout(new FlowLayout()); panel2.setBackground(Color.ORANGE); for (int i = 0; i < 5; i++) panel1.add(new JCheckBox("CheckBox " + (i + 1))); f.add(panel1, BorderLayout.WEST); f.add(panel2, BorderLayout.CENTER); f.setVisible(true);/* ww w. j a va 2s .c o m*/ f.setSize(300, 300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
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.setOpaque(true);/*from www . ja va2 s . c o m*/ contentPane.setBackground(Color.WHITE); contentPane.setLayout(null); JLabel label = new JLabel("This JPanel uses Absolute Positioning", JLabel.CENTER); label.setSize(300, 30); label.setLocation(5, 5); JButton button = new JButton("USELESS"); button.setSize(100, 30); button.setLocation(95, 45); contentPane.add(label); contentPane.add(button); frame.setContentPane(contentPane); frame.setSize(310, 125); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:BoxLayoutDemo.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); LayoutManager layout = new BoxLayout(panel, BoxLayout.X_AXIS); panel.setLayout(layout);// w w w.j av a2 s . c o m panel.add(new JLabel("a")); panel.add(new JLabel("b")); panel.add(new JLabel("c")); panel.add(new JLabel("d")); panel.add(new JLabel("e")); panel.add(new JLabel("f")); frame.add(panel); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setSize(300, 200);//from w ww . j ava 2 s . c o m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton redButton = new JButton("Red"); JButton greenButton = new JButton("Green"); JButton blueButton = new JButton("Blue"); class Listener extends JPanel implements ActionListener { public void actionPerformed(ActionEvent event) { Color color; if (event.getSource() == redButton) { color = Color.red; redButton.setBackground(color); panel.setBackground(color); } else if (event.getSource() == greenButton) { color = Color.green; greenButton.setBackground(color); panel.setBackground(color); } else { color = Color.blue; blueButton.setBackground(color); panel.setBackground(color); } setBackground(color); repaint(); } } redButton.addActionListener(new Listener()); greenButton.addActionListener(new Listener()); blueButton.addActionListener(new Listener()); panel.add(redButton); panel.add(greenButton); panel.add(blueButton); frame.add(panel); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JButton btn = new JButton("Test"); JPanel panel = new JPanel(); panel.add(btn);//from w w w. j av a 2s. com JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.add("Tab1", panel); frame.add(tabbedPane, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setMinimumSize(new Dimension(300, 300)); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { JFrame f = new JFrame(); f.setLayout(new BorderLayout()); JPanel panel = new JPanel(); JButton button = new JButton("A-ha!"); button.setAlignmentX(Component.CENTER_ALIGNMENT); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.add(Box.createVerticalGlue()); panel.add(button);/*from w w w .j a v a 2s . c o m*/ panel.add(Box.createVerticalGlue()); f.getContentPane().add(panel); f.setVisible(true); }