Example usage for javax.swing JFrame setLocation

List of usage examples for javax.swing JFrame setLocation

Introduction

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

Prototype

@Override
public void setLocation(int x, int y) 

Source Link

Document

The method changes the geometry-related data.

Usage

From source file:Main.java

public static void main(String[] argv) {
    JTree tree = new JTree();
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    int treeSelectedRows[] = { 3, 1 };
    tree.setSelectionRows(treeSelectedRows);
    TreeSelectionListener treeSelectionListener = new TreeSelectionListener() {

        @Override//from   w w  w  . ja  v  a  2s .c  o m
        public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
            JTree treeSource = (JTree) treeSelectionEvent.getSource();
            System.out.println("Min: " + treeSource.getMinSelectionRow());
            System.out.println("Max: " + treeSource.getMaxSelectionRow());
            System.out.println("Lead: " + treeSource.getLeadSelectionRow());
            System.out.println("Row: " + treeSource.getSelectionRows()[0]);
        }
    };
    tree.addTreeSelectionListener(treeSelectionListener);
    JFrame frame = new JFrame("JTree With Multi-Discontiguous selection");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(tree));
    frame.setPreferredSize(new Dimension(380, 320));
    frame.setLocation(150, 150);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    int nb = 4;//from   w w w .j  a  v a  2s. c o  m
    final int frameCount = nb;

    for (int i = 0; i < frameCount; i++) {
        JFrame frame = new JFrame("Frame number " + i);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        JPanel p = new JPanel(new BorderLayout());
        p.add(new JLabel("Click on the corner to close..."), BorderLayout.CENTER);
        frame.setContentPane(p);
        frame.setSize(200, 200);
        frame.setLocation(100 + 20 * i, 100 + 20 * i);
        frame.setVisible(true);
    }
}

From source file:REDemo.java

/** "main program" method - construct and show */
public static void main(String[] av) {
    JFrame f = new JFrame("REDemo");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    REDemo comp = new REDemo();
    f.setContentPane(comp);/*from www.j  av  a 2  s .c  om*/
    f.pack();
    f.setLocation(200, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    final JFrame jf = new JFrame("JIFrameDemo Main Window");

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    screenSize.width -= 42;// w  w  w . j a  va 2  s.c  o m
    screenSize.height -= 42;
    jf.setSize(screenSize);
    jf.setLocation(20, 20);

    JMenuBar mb = new JMenuBar();
    jf.setJMenuBar(mb);
    JMenu fm = new JMenu("File");
    mb.add(fm);
    JMenuItem mi;
    fm.add(mi = new JMenuItem("Exit"));
    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });

    JDesktopPane dtp = new JDesktopPane();
    //dtp.setBackground(Color.GREEN);
    jf.setContentPane(dtp);

    JInternalFrame mboxFrame = new JInternalFrame("Mail Reader", true, true, true, true);
    JLabel reader = new JLabel("Mail Reader Would Be Here");
    mboxFrame.setContentPane(reader);
    mboxFrame.setSize(400, 300);
    mboxFrame.setLocation(50, 50);
    mboxFrame.setVisible(true);
    dtp.add(mboxFrame);

    JInternalFrame compFrame = new JInternalFrame("Compose Mail", true, true, true, true);
    JLabel composer = new JLabel("Mail Compose Would Be Here");
    compFrame.setContentPane(composer);
    compFrame.setSize(300, 200);
    compFrame.setLocation(200, 200);
    compFrame.setVisible(true);
    dtp.add(compFrame);

    JInternalFrame listFrame = new JInternalFrame("Users", true, true, true, true);
    JLabel list = new JLabel("List of Users Would Be Here");
    listFrame.setContentPane(list);
    listFrame.setLocation(400, 400);
    listFrame.setSize(500, 200);
    listFrame.setVisible(true);
    dtp.add(listFrame);

    jf.setVisible(true);
    jf.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            jf.setVisible(false);
            jf.dispose();
            System.exit(0);
        }
    });
}

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  .  j  av a2  s .c  o  m
    frame.show();
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    DefaultListModel<String> dlm = new DefaultListModel();
    String[] modelElems = { "Apple", "Orange", "Banana" };
    for (int i = 0; i < modelElems.length; i++)
        dlm.add(i, modelElems[i]);//  ww  w  . j a v a2 s.  c  o  m

    JList<String> lstFruitList = new JList(dlm);
    lstFruitList.setVisible(true);

    JPanel p = new JPanel();
    p.add(lstFruitList);
    f.add(p);
    f.setLocation(0, 0);
    f.setSize(400, 400);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JTextArea textarea = new JTextArea();
    textarea.setDragEnabled(true);//from  www . j a  v  a2 s .c  om

    textarea.setText("Drag target");

    frame.getContentPane().add(BorderLayout.CENTER, textarea);

    JTextField textarea1 = new JTextField();
    textarea1.setText("Drop target");
    frame.getContentPane().add(BorderLayout.SOUTH, textarea1);

    frame.setSize(500, 300);
    frame.setVisible(true);
    frame.setLocation(100, 100);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setUndecorated(true);//from w w  w.jav a2s  .  co  m
    frame.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            point.x = e.getX();
            point.y = e.getY();
        }
    });
    frame.addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            Point p = frame.getLocation();
            frame.setLocation(p.x + e.getX() - point.x, p.y + e.getY() - point.y);
        }
    });

    frame.setSize(300, 300);
    frame.setLocation(200, 200);
    frame.setLayout(new BorderLayout());

    frame.getContentPane().add(new JLabel("Drag to move", JLabel.CENTER), BorderLayout.CENTER);

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Menu");
    menuBar.add(menu);
    JMenuItem item = new JMenuItem("Exit");
    item.addActionListener(e -> System.exit(0));
    menu.add(item);
    frame.setJMenuBar(menuBar);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.add(new JPanel() {
        @Override/*from  ww w .  ja v  a 2s.c  o  m*/
        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) {
    JFrame f = new JFrame();
    f.add(new JPanel() {
        @Override/*from  w w w .  ja  v  a  2s  .  co  m*/
        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);
}