Example usage for javax.swing JFrame getHeight

List of usage examples for javax.swing JFrame getHeight

Introduction

In this page you can find the example usage for javax.swing JFrame getHeight.

Prototype

public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

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);/*w ww.  j  ava 2s.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:ALineBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Line Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border thinBorder = LineBorder.createBlackLineBorder();
    Border thickBorder = new LineBorder(Color.white, 12);
    Border roundedBorder = new LineBorder(Color.black, 12, true);
    JButton thinButton = new JButton("1 Pixel");
    thinButton.setBorder(thinBorder);/* ww  w.ja va  2s  . c om*/
    JButton thickButton = new JButton("12 Pixel");
    thickButton.setBorder(thickBorder);
    JButton roundedButton = new JButton("Rounded 12 Pixel");
    roundedButton.setBorder(roundedBorder);
    Container contentPane = frame.getContentPane();
    contentPane.add(thinButton, BorderLayout.NORTH);
    contentPane.add(thickButton, BorderLayout.CENTER);
    contentPane.add(roundedButton, BorderLayout.SOUTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.setVisible(true);
}

From source file:ALineBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Line Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Border thinBorder = LineBorder.createBlackLineBorder();
    Border thickBorder = new LineBorder(Color.WHITE, 12);
    Border roundedBorder = new LineBorder(Color.BLACK, 2, true);

    JButton thinButton = new JButton("1 Pixel");
    thinButton.setBorder(thinBorder);/*from  www  . j a  va2s. c  o  m*/

    JButton thickButton = new JButton("12 Pixel");
    thickButton.setBorder(thickBorder);

    JButton roundedButton = new JButton("Rounded 2 Pixel");
    roundedButton.setBorder(roundedBorder);

    Container contentPane = frame.getContentPane();
    contentPane.add(thinButton, BorderLayout.NORTH);
    contentPane.add(thickButton, BorderLayout.CENTER);
    contentPane.add(roundedButton, BorderLayout.SOUTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.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();/*from   ww  w  .  ja v a  2s  .  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  w w .j  a v a  2 s. co  m*/
    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  ww . j a  va2  s  . c o  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();
}

From source file:Main.java

public static void moveToCenter(JFrame frame) {
    int windowWidth = frame.getWidth();
    int windowHeight = frame.getHeight();
    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();
    int screenWidth = screenSize.width;
    int screenHeight = screenSize.height;
    frame.setLocation(screenWidth / 2 - windowWidth / 2, screenHeight / 2 - windowHeight / 2);
}

From source file:Main.java

private static void centerOn(JFrame f, GraphicsConfiguration gc) {
    Rectangle bounds = gc.getBounds();
    int x = bounds.x + ((bounds.width - f.getWidth()) / 2);
    int y = bounds.y + ((bounds.height - f.getHeight()) / 2);
    f.setLocation(x, y);/*from  w  ww. j a v  a 2  s  . c o m*/
}

From source file:Main.java

/**
 * Used to centre the dialogs.//from  ww  w. ja  v a2 s  .  c o m
 */
public static void centreOnParent(final JDialog dialog, final JFrame frame) {
    int x = frame.getX();
    x += (frame.getWidth() - dialog.getWidth()) / 2;

    int y = frame.getY();
    y += (frame.getHeight() - dialog.getHeight()) / 2;

    dialog.setLocation(x, y);
}

From source file:Main.java

/**
 * Centers a {@link JFrame} on screen./*w  w  w.jav a 2s .c  om*/
 */
public static void centerFrameOnScreen(JFrame frame) {
    final Dimension position = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((position.width - frame.getWidth()) / 2, (position.height - frame.getHeight()) / 2);
}