Example usage for javax.swing JFrame setBounds

List of usage examples for javax.swing JFrame setBounds

Introduction

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

Prototype

public void setBounds(int x, int y, int width, int height) 

Source Link

Document

The width or height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .

Usage

From source file:Main.java

public static void main(String[] args) {
    final JFrame parent = new JFrame("Parent Frame");
    parent.setLayout(new FlowLayout());
    parent.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    parent.setBounds(100, 100, 300, 200);
    parent.setVisible(true);/* ww w.jav  a2  s.  c om*/
    JDialog dialog1 = new JDialog(parent, "Dialog1 - Modeless Dialog");
    dialog1.setBounds(200, 200, 300, 200);
    dialog1.setVisible(true);

    JDialog dialog2 = new JDialog(parent, "Dialog2 - Document-Modal Dialog",
            Dialog.ModalityType.DOCUMENT_MODAL);
    dialog2.setBounds(300, 300, 300, 200);

    JDialog dialog3 = new JDialog(dialog2, "Dialog3 - Modeless Dialog");
    dialog3.setBounds(400, 400, 300, 200);
    dialog3.setVisible(true);

    dialog2.setVisible(true);

}

From source file:ApplicationModalDialogWithExcludeDemo.java

public static void main(String[] args) {
    final JFrame parent1 = new JFrame("Parent Frame 1");
    parent1.setLayout(new FlowLayout());
    parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    parent1.setBounds(100, 100, 200, 150);
    parent1.setVisible(true);/*from w ww  .  j  a  v a2 s  .com*/

    JFrame parent2 = new JFrame("Parent Frame 2");
    parent2.setBounds(500, 100, 300, 150);
    parent2.setVisible(true);

    JFrame parent3 = new JFrame("Parent Frame 3 - Excluded");
    parent3.setBounds(300, 400, 300, 150);
    parent3.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
    parent3.setVisible(true);

    JDialog dialog = new JDialog(parent1, "Application-Modal Dialog", Dialog.ModalityType.APPLICATION_MODAL);
    dialog.setBounds(300, 200, 300, 150);
    dialog.setVisible(true);

}

From source file:Clock.java

public static void main(String args[]) {
    JFrame window = new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setBounds(30, 30, 300, 300);
    Clock clock = new Clock();
    window.getContentPane().add(clock);/* w  ww  . ja  v a2s. c om*/
    window.setVisible(true);
    clock.start();
}

From source file:Main.java

public static void main(String args[]) {
    String[] mainData = { "-Select-", "Sel 1", "Sel 2", "Sel 3" };
    String[] subData1 = { "Sub Sel 11", "Sub Sel 12", "Sub Sel 13" };
    String[] subData2 = { "Sub Sel 21", "Sub Sel 22", "Sub Sel 23" };
    String[] subData3 = { "Sub Sel 31", "Sub Sel 32", "Sub Sel 33" };
    DefaultComboBoxModel boxModel = new DefaultComboBoxModel();
    JComboBox box1 = new JComboBox(mainData), box2 = new JComboBox();
    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.add(box1);/*from   w  ww. ja  va2 s .  co m*/
    frame.add(box2);
    box2.setVisible(false);
    box2.setModel(boxModel);
    frame.setBounds(200, 200, 500, 200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    box1.addItemListener(e -> {
        box2.setVisible(true);
        boxModel.removeAllElements();
        if (box1.getSelectedIndex() == 0) {
            box2.setVisible(false);
        } else if (box1.getSelectedIndex() == 1) {
            for (String s : subData1) {
                boxModel.addElement(s);
            }
        } else if (box1.getSelectedIndex() == 2) {
            for (String s : subData2) {
                boxModel.addElement(s);
            }
        } else if (box1.getSelectedIndex() == 3) {
            for (String s : subData3) {
                boxModel.addElement(s);
            }
        }
    });
}

From source file:CenteringaWindow.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is the Window Title");
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    int windowWidth = 400;
    int windowHeight = 150;
    // set position and size
    aWindow.setBounds(center.x - windowWidth / 2, center.y - windowHeight / 2, windowWidth, windowHeight);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setVisible(true); // Display the window
}

From source file:CreatingCursors.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is the Window Title");
    Toolkit theKit = aWindow.getToolkit(); // Get the window toolkit
    Dimension wndSize = theKit.getScreenSize(); // Get screen size
    // Set the position to screen center & size to half screen size
    aWindow.setBounds(wndSize.width / 4, wndSize.height / 4, // Position
            wndSize.width / 2, wndSize.height / 2); // Size
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    aWindow.setVisible(true); // Display the window
}

From source file:org.jfree.chart.demo.MemoryUsageDemo.java

public static void main(String args[]) {
    JFrame jframe = new JFrame("Memory Usage Demo");
    MemoryUsageDemo memoryusagedemo = new MemoryUsageDemo(30000);
    jframe.getContentPane().add(memoryusagedemo, "Center");
    jframe.setBounds(200, 120, 600, 280);
    jframe.setVisible(true);/*from w w w  .java2 s  . c o  m*/
    (memoryusagedemo.new DataGenerator(100)).start();
    jframe.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent windowevent) {
            System.exit(0);
        }

    });
}

From source file:unusedClasses.MemoryUsageDemo.java

public static void main(String[] paramArrayOfString) {
    JFrame localJFrame = new JFrame("Memory Usage Demo");
    MemoryUsageDemo localMemoryUsageDemo = new MemoryUsageDemo(30000);
    localJFrame.getContentPane().add(localMemoryUsageDemo, "Center");
    localJFrame.setBounds(200, 120, 600, 280);
    localJFrame.setVisible(true);/*from   w w  w. ja  va  2s .  co m*/
    MemoryUsageDemo tmp56_55 = localMemoryUsageDemo;
    tmp56_55.getClass();
    tmp56_55.new DataGenerator(100).start();
    localJFrame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent paramWindowEvent) {
            System.exit(0);
        }
    });
}

From source file:Main.java

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

    // Add a close button
    JButton closeButton = new JButton("Close");
    contentPane.add(closeButton);/*  ww w . jav  a2 s  . c  om*/

    // set the size of the frame 300 x 200
    frame.setBounds(50, 50, 300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JFrame frame = new JFrame();
    JLabel label = new JLabel("Label with image in Tooltip!");
    label.setToolTipText("<html><img src=\"" + Main.class.getResource("tooltip.gif") + "\"> Tooltip ");
    label.setHorizontalAlignment(JLabel.CENTER);
    frame.setContentPane(label);/*from w  w  w. j a v a2s  .  c om*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(100, 100, 200, 100);
    frame.setVisible(true);

}