List of usage examples for java.awt Dimension Dimension
public Dimension(int width, int height)
From source file:Main.java
public static void main(String[] args) { JLabel label = new JLabel("Hello"); label.setOpaque(true);//from w w w . j av a 2 s.c om label.setBackground(Color.red); JPanel bottomPanel = new JPanel(new BorderLayout()); bottomPanel.add(label, BorderLayout.LINE_END); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(bottomPanel, BorderLayout.PAGE_END); mainPanel.setPreferredSize(new Dimension(400, 400)); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("Label Demo"); f.setLayout(new FlowLayout()); f.setSize(300, 200);//from w ww . ja v a 2 s. c o m f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("java2s.com"); Border border = BorderFactory.createLineBorder(Color.BLACK); label.setBorder(border); label.setPreferredSize(new Dimension(150, 100)); label.setText("Centered"); label.setHorizontalAlignment(JLabel.CENTER); label.setVerticalAlignment(JLabel.CENTER); f.add(label); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int x = 5;/* w ww . j a v a2 s . c o m*/ int y = 5; JPanel panel = new JPanel(); panel.setLayout(new GridLayout(x, y)); for (int i = 0; i < x * y; i++) { JButton button = new JButton(String.valueOf(i)); button.setPreferredSize(new Dimension(100, 100)); panel.add(button); } JPanel container = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); container.add(panel); JScrollPane scrollPane = new JScrollPane(container); f.getContentPane().add(scrollPane); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTabbedPane tabbedPane = new JTabbedPane(); for (int i = 0; i < 5; i++) { tabbedPane.add("Tab " + i, new JLabel("Label " + i, SwingConstants.CENTER)); }//from w w w . j a v a 2 s . c om tabbedPane.getModel().addChangeListener(e -> { JLabel label = (JLabel) tabbedPane.getSelectedComponent(); System.out.println(label.getText()); }); tabbedPane.setPreferredSize(new Dimension(500, 300)); JFrame frame = new JFrame(); frame.getContentPane().add(tabbedPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.setSize(240, 250);//ww w .jav a2 s. com f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JScrollPane jscrlpLabel = new JScrollPane( new JLabel("<html>A<br>B<br>C<br>D<br>E<br>F<br>G<br>H<br></html>.")); jscrlpLabel.setPreferredSize(new Dimension(200, 100)); JLabel label = new JLabel("Option"); JCheckBox a = new JCheckBox("A"); JCheckBox b = new JCheckBox("B"); JCheckBox c = new JCheckBox("C"); JCheckBox d = new JCheckBox("D"); JCheckBox e = new JCheckBox("E"); Box box = Box.createVerticalBox(); box.add(label); box.add(a); box.add(b); box.add(c); box.add(d); box.add(e); JScrollPane jscrlpBox = new JScrollPane(box); jscrlpBox.setPreferredSize(new Dimension(140, 90)); f.add(jscrlpLabel); f.add(jscrlpBox); 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 ww w . j av a 2 s .co m 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);//w w w . java 2 s. co m 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[] args) { JFrame frame = new JFrame(); frame.setPreferredSize(new Dimension(300, 280)); Main ch = new Main(); frame.getContentPane().add(ch);//from w w w.j a va 2 s.c o m frame.setUndecorated(true); MoveMouseListener mml = new MoveMouseListener(ch); ch.addMouseListener(mml); ch.addMouseMotionListener(mml); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); URL url = new URL("http://www.java2s.com/style/download.png"); Image image = ImageIO.read(url); ImagePanel ip = new ImagePanel(new GridLayout(4, 4, 20, 20)); ip.setPreferredSize(new Dimension(640, 480)); f.setContentPane(ip);//ww w. j av a 2s . com f.pack(); f.setVisible(true); ip.setImage(new ImageIcon(image)); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jtp.setPreferredSize(new Dimension(400, 200)); createTab("Reds", Color.RED); f.add(jtp, BorderLayout.CENTER); f.pack();//ww w . j ava 2 s . c o m f.setVisible(true); }