Example usage for javax.swing JFrame setLocationRelativeTo

List of usage examples for javax.swing JFrame setLocationRelativeTo

Introduction

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

Prototype

public void setLocationRelativeTo(Component c) 

Source Link

Document

Sets the location of the window relative to the specified component according to the following scenarios.

Usage

From source file:GradientsRedYellow.java

public static void main(String[] args) {

    JFrame frame = new JFrame("GradientsRedYellow");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new GradientsRedYellow());
    frame.setSize(350, 350);//from   ww w  .  j  a v  a2s .co m
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:BlurredImage.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Blurred Image");
    frame.add(new BlurredImage());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);/*from   w  w  w . j  a v a2  s  .c  o m*/
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:RotatedText.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Rotated text");
    frame.add(new RotatedText());
    frame.setSize(400, 300);//from w w w.  ja  v  a2 s. co  m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:TextAttributesUnderline.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Text attributes");
    frame.add(new TextAttributesUnderline());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(620, 190);/*from ww  w . j a v a 2  s.c  o  m*/
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:TextAttributesBackground.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Text attributes");
    frame.add(new TextAttributesBackground());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(620, 190);/*from   ww w .  j  a v a  2 s. c o m*/
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:TextAttributesSuperscript.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Text attributes");
    frame.add(new TextAttributesSuperscript());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(620, 190);/*from   w  w  w  .  j ava  2  s.  co  m*/
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    JTextField tf1 = new JTextField(10);
    panel.add(tf1);//w w  w  . j a  va2 s  .c  o m
    JTextField tf2 = new JTextField(10);
    panel.add(tf2);

    new TextPrompt("First Name", tf1);
    new TextPrompt("Last Name", tf2);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:ButtonModel.java

public static void main(String[] args) {
    final JButton ok = new JButton("ok");

    JCheckBox cb = new JCheckBox("Enabled", true);

    ok.setBounds(40, 30, 80, 25);/*ww  w  .  j a  v a  2  s .  co  m*/
    ok.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            DefaultButtonModel model = (DefaultButtonModel) ok.getModel();
            if (model.isEnabled())
                System.out.println("Enabled: true");
            else
                System.out.println("Enabled: false");

            if (model.isArmed())
                System.out.println("Armed: true");
            else
                System.out.println("Armed: false");

            if (model.isPressed())
                System.out.println("Pressed: true");
            else
                System.out.println("Pressed: false");
        }

    });

    cb.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (ok.isEnabled())
                ok.setEnabled(false);
            else
                ok.setEnabled(true);
        }
    });

    JFrame f = new JFrame();
    f.setLayout(new FlowLayout());
    f.add(ok);
    f.add(cb);
    f.setSize(350, 250);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:TextAttributesStrikeThrough.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Text attributes");
    frame.add(new TextAttributesStrikeThrough());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(620, 190);/*from   ww  w. j  a  va2 s .  c  om*/
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {

    JTree tree = new JTree() {
        protected void setExpandedState(TreePath path, boolean state) {

            if (state) {
                super.setExpandedState(path, state);
            }/*from   w w w.  ja va2 s  .com*/
        }
    };

    JFrame frame = new JFrame("Ignore all collapse requests");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(tree));
    frame.setSize(380, 320);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

}