List of usage examples for java.awt Dimension Dimension
public Dimension(int width, int height)
From source file:Main.java
/** * Get the full screen size recognizing multiple monitor. * /*w ww . j a v a 2s . c o m*/ * @return full screen size */ public static Dimension getFullScreenSize() { Rectangle2D result = new Rectangle2D.Double(); GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (GraphicsDevice gd : localGE.getScreenDevices()) { for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) { Rectangle2D.union(result, graphicsConfiguration.getBounds(), result); } } return new Dimension((int) result.getWidth(), (int) result.getHeight()); }
From source file:MainClass.java
MainClass() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); p.setPreferredSize(new Dimension(200, 200)); JTable jt = new JTable(10, 3); p.add(new JScrollPane(jt)); getContentPane().add(p);/*w w w . j ava 2 s . c o m*/ pack(); setVisible(true); }
From source file:Main.java
public Main() { setPreferredSize(new Dimension(500, 500)); getContentPane().setLayout(new BorderLayout()); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(4, 4, 4, 4); panel.add(new JLabel("Label"), c); panel.add(new JTextField(20), c); c.gridwidth = GridBagConstraints.REMAINDER; panel.add(new JButton("btn"), c); c.gridwidth = 1;//from w w w . jav a 2s. c o m panel.add(new JLabel("Name"), c); panel.add(new JTextField(20), c); c.gridwidth = GridBagConstraints.REMAINDER; panel.add(new JButton("btn"), c); c.weighty = 1.0; panel.add(Box.createGlue(), c); add(panel, BorderLayout.LINE_START); pack(); setVisible(true); }
From source file:MainClass.java
MainClass() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); p.setPreferredSize(new Dimension(300, 50)); JScrollBar jsb;//from www . j a va 2 s . c o m jsb = new JScrollBar(Adjustable.HORIZONTAL, 0, 1, 0, 100); jsb.setPreferredSize(new Dimension(200, 20)); p.add(jsb); getContentPane().add(p); pack(); setVisible(true); }
From source file:Main.java
public Main() { childPanel1.setBackground(Color.red); childPanel1.setPreferredSize(new Dimension(300, 40)); childPanel2.setBackground(Color.blue); childPanel2.setPreferredSize(new Dimension(300, 40)); childPanel3.setBackground(Color.yellow); childPanel3.setPreferredSize(new Dimension(300, 40)); JButton myButton = new JButton("Add Component "); myButton.addActionListener(e -> { add(childPanel2, BorderLayout.CENTER); pack();//from w w w. j av a 2 s. co m }); setLocation(10, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(childPanel3, BorderLayout.CENTER); add(myButton, BorderLayout.SOUTH); pack(); setVisible(true); }
From source file:Main.java
public static void setWidth(JComponent component, int width) { component.setSize(new Dimension(width, component.getHeight())); }
From source file:Main.java
public Main() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { @Override//from w ww. jav a2 s. c o m public Dimension getPreferredSize() { return new Dimension(300, 300); } }; frame.add(panel); frame.addWindowStateListener(new WindowAdapter() { @Override public void windowStateChanged(WindowEvent we) { super.windowStateChanged(we); if (we.getNewState() == Frame.ICONIFIED) { System.out.println("Here"); } } }); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public Main() { JPanel parentPanel = new JPanel(); parentPanel.setLayout(new BorderLayout(10, 10)); JPanel childPanel1 = new JPanel(); childPanel1.setBackground(Color.red); childPanel1.setPreferredSize(new Dimension(300, 40)); JPanel childPanel2 = new JPanel(); childPanel2.setBackground(Color.blue); childPanel2.setPreferredSize(new Dimension(800, 600)); JButton myButton = new JButton("Add Component "); myButton.addActionListener(e -> { parentPanel.remove(childPanel1); parentPanel.add(childPanel2, BorderLayout.CENTER); parentPanel.revalidate();/*w w w . j av a 2 s .c o m*/ parentPanel.repaint(); pack(); }); setLocation(10, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); parentPanel.add(childPanel1, BorderLayout.CENTER); parentPanel.add(myButton, BorderLayout.SOUTH); add(parentPanel); pack(); setVisible(true); }
From source file:Main.java
public static void setMaximumWidth(JComponent component, int width) { component.setMaximumSize(new Dimension(width, (int) component.getMaximumSize().getHeight())); }
From source file:Main.java
public static void setMaximumHeight(JComponent component, int height) { component.setMaximumSize(new Dimension((int) component.getMaximumSize().getWidth(), height)); }