List of usage examples for javax.swing JFrame getWidth
public int getWidth()
From source file:Main.java
public static void main(String[] args) throws Exception { final JTree tree = new JTree(getTreeModel()); tree.setCellRenderer(new MyTreeCellRenderer()); HyperlinkMouseListener listener = new HyperlinkMouseListener(tree); tree.addMouseListener(listener);//from w w w .j a v a 2s .c om tree.addMouseMotionListener(listener); JFrame f = new JFrame(Main.class.getSimpleName()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(tree), BorderLayout.CENTER); f.pack(); f.setSize(f.getWidth() + 100, f.getHeight() + 100); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(Main.class.getSimpleName()); DefaultTreeModel model = getTreeModel(); JTree tree1 = new JTree(model); JTree tree2 = new JTree(model); frame.add(new JScrollPane(tree1), BorderLayout.WEST); frame.add(new JScrollPane(tree2), BorderLayout.EAST); frame.pack();/*from www . j av a2 s . c o m*/ frame.setSize(frame.getWidth() + 50, frame.getHeight() + 140); frame.setVisible(true); Timer t = new Timer(2000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); root.add(new DefaultMutableTreeNode("A new node")); model.nodesWereInserted(root, new int[] { root.getChildCount() - 1 }); tree1.expandRow(0); tree2.expandRow(0); frame.revalidate(); } }); t.start(); }
From source file:Main.java
public static void main(String[] args) { JPanel statusBar = new JPanel(new FlowLayout(FlowLayout.LEFT)); statusBar.setBorder(new CompoundBorder(new LineBorder(Color.DARK_GRAY), new EmptyBorder(4, 4, 4, 4))); final JLabel status = new JLabel(); statusBar.add(status);//from w w w .j a va 2s . c om JLabel content = new JLabel("Content in the middle"); content.setHorizontalAlignment(JLabel.CENTER); final JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(content); frame.add(statusBar, BorderLayout.SOUTH); frame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { status.setText(frame.getWidth() + "x" + frame.getHeight()); } }); frame.setBounds(20, 20, 200, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = (JPanel) frame.getContentPane(); panel.setLayout(new BorderLayout()); JTextField field = new JTextField(20); Main spinner = new Main(); panel.add(field, "Center"); panel.add(spinner, "East"); Dimension dim = frame.getToolkit().getScreenSize(); frame.setLocation(dim.width / 2 - frame.getWidth() / 2, dim.height / 2 - frame.getHeight() / 2); frame.pack();/*w w w .java2 s. co m*/ frame.show(); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.add(new JPanel() { @Override/*from w ww. j a v a 2 s . com*/ public Dimension getPreferredSize() { return new Dimension(320, 240); } }); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int) rect.getMaxX() - f.getWidth(); int y = (int) rect.getMaxY() - f.getHeight(); f.setLocation(x, y); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.add(new JPanel() { @Override/*from w ww. j av a2 s. com*/ public Dimension getPreferredSize() { return new Dimension(320, 240); } }); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int) rect.getMaxX() - f.getWidth(); int y = 0; f.setLocation(x, y); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(Main.class.getSimpleName()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BufferedImage bi = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel(new ImageIcon(bi)); panel.add(label);//from w ww. j a v a 2 s. c o m MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1); ((JPanel) e.getSource()).scrollRectToVisible(r); } }; panel.addMouseMotionListener(doScrollRectToVisible); panel.setAutoscrolls(true); f.add(new JScrollPane(panel)); f.pack(); f.setSize(f.getWidth() / 2, f.getHeight() / 2); f.setVisible(true); }
From source file:DateTimeEditor.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = (JPanel) frame.getContentPane(); panel.setLayout(new BorderLayout()); JTextField field = new JTextField(20); Spinner spinner = new Spinner(); panel.add(field, "Center"); panel.add(spinner, "East"); Dimension dim = frame.getToolkit().getScreenSize(); frame.setLocation(dim.width / 2 - frame.getWidth() / 2, dim.height / 2 - frame.getHeight() / 2); frame.pack();/* w ww. j ava2s .c o m*/ frame.show(); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame Main = new JFrame("Gradient Mask"); JLabel imageLayer = new JLabel(); JLabel maskLayer = new JLabel(); BufferedImage image = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); BufferedImage gradientMask = new GradientImage(image.getWidth(), image.getHeight(), new Color[] { new Color(255, 255, 255, 125), Color.BLACK }, GradientImage.RADIAL_FROM_CENTER) .getImage();//from w ww. j a v a2 s . c om Main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Main.setBounds(100, 50, image.getWidth(), image.getHeight()); imageLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight()); maskLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight()); imageLayer.setIcon(new ImageIcon((Image) image)); maskLayer.setIcon(new ImageIcon((Image) gradientMask)); Main.getContentPane().add(imageLayer); imageLayer.add(maskLayer); Main.setVisible(true); }
From source file:DateTimeEditor.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0);// w w w . j a v a 2s. co m } }); JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(new EmptyBorder(5, 5, 5, 5)); frame.setContentPane(panel); final DateTimeEditor field = new DateTimeEditor(DateTimeEditor.DATETIME, DateFormat.FULL); panel.add(field, "North"); JPanel buttonBox = new JPanel(new GridLayout(2, 2)); JButton showDateButton = new JButton("Show Date"); buttonBox.add(showDateButton); final JComboBox timeDateChoice = new JComboBox(); timeDateChoice.addItem("Time"); timeDateChoice.addItem("Date"); timeDateChoice.addItem("Date/Time"); timeDateChoice.setSelectedIndex(2); timeDateChoice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { field.setTimeOrDateType(timeDateChoice.getSelectedIndex()); } }); buttonBox.add(timeDateChoice); JButton toggleButton = new JButton("Toggle Enable"); buttonBox.add(toggleButton); showDateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println(field.getDate()); } }); toggleButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { field.setEnabled(!field.isEnabled()); } }); panel.add(buttonBox, "South"); final JComboBox lengthStyleChoice = new JComboBox(); lengthStyleChoice.addItem("Full"); lengthStyleChoice.addItem("Long"); lengthStyleChoice.addItem("Medium"); lengthStyleChoice.addItem("Short"); lengthStyleChoice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { field.setLengthStyle(lengthStyleChoice.getSelectedIndex()); } }); buttonBox.add(lengthStyleChoice); frame.pack(); Dimension dim = frame.getToolkit().getScreenSize(); frame.setLocation(dim.width / 2 - frame.getWidth() / 2, dim.height / 2 - frame.getHeight() / 2); frame.show(); }