Example usage for javax.swing JFrame setLocationByPlatform

List of usage examples for javax.swing JFrame setLocationByPlatform

Introduction

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

Prototype

public void setLocationByPlatform(boolean locationByPlatform) 

Source Link

Document

Sets whether this Window should appear at the default location for the native windowing system or at the current location (returned by getLocation ) the next time the Window is made visible.

Usage

From source file:Main.java

public static void main(String[] args) {
    int ROW_HEIGHT = 40;
    String[] TABLE_COLUMNS = { "Foo", "Bar" };
    DefaultTableModel tableModel = new DefaultTableModel(TABLE_COLUMNS, 2);
    JTable table = new JTable(tableModel);
    table.setRowHeight(ROW_HEIGHT);/*w w  w .j ava  2s  .  c o  m*/
    JScrollPane scrollpane = new JScrollPane(table);
    JButton addRowBtn = new JButton(new AbstractAction("Add Row") {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            tableModel.addRow(new String[] { "", "" });
        }
    });
    JPanel btnPanel = new JPanel();
    btnPanel.add(addRowBtn);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(scrollpane, BorderLayout.CENTER);
    f.getContentPane().add(btnPanel, BorderLayout.PAGE_END);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Main swapper = new Main();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(swapper.getMainPanel());
    frame.setJMenuBar(swapper.getMenuBar());
    frame.pack();//from  w w  w .ja  v  a 2s .  c  o  m
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:Main.java

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

    DefaultTableModel model = new DefaultTableModel();
    model.setColumnIdentifiers(new Object[] { "Column 1", "Column 2", "Column 3" });

    JTable table = new JTable(model);
    for (int count = 0; count < 3; count++) {
        model.insertRow(count, new Object[] { count, "name", "age" });
    }/*ww w. ja  v  a  2  s  .com*/
    table.setRowHeight(1, 30);

    frame.add(new JScrollPane(table));
    frame.setLocationByPlatform(true);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel contentPane = new JPanel();
    contentPane.setOpaque(true);/*from   w  w w .  j  a v  a 2s. c o  m*/
    contentPane.setBackground(Color.WHITE);
    contentPane.setLayout(null);

    JLabel label = new JLabel("This JPanel uses Absolute Positioning", JLabel.CENTER);
    label.setSize(300, 30);
    label.setLocation(5, 5);

    JButton button = new JButton("USELESS");
    button.setSize(100, 30);
    button.setLocation(95, 45);

    contentPane.add(label);
    contentPane.add(button);

    frame.setContentPane(contentPane);
    frame.setSize(310, 125);
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel panel = new JPanel() {
        @Override//from  w  w  w  .j  a v  a  2s  .c om
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            int y = 0;
            for (int size = 4; size <= 24; size += 2) {
                g.setFont(new Font("Arial", Font.BOLD, size));
                g.drawString("Name", 0, y);
                int heightOfFont = g.getFontMetrics().getHeight();
                y += heightOfFont;
            }
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(300, 300);
        }
    };
    frame.add(panel);
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
    frame.pack();

}

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new GridLayout(1, 2, 2, 2));

    JTextArea tArea1 = new JTextArea();
    tArea1.setLineWrap(true);// www .  jav a 2  s  . c om
    JTextArea tArea2 = new JTextArea();
    tArea2.setLineWrap(true);
    tArea1.setText("I got a long long line of text in my JTextArea");
    tArea2.setText("I got a long long line of text in my JTextArea");

    JScrollPane scroller1 = new JScrollPane();
    JScrollPane scroller2 = new JScrollPane();
    scroller1.setViewportView(tArea1);
    scroller2.setViewportView(tArea2);

    contentPane.add(scroller1);
    contentPane.add(scroller2);

    frame.setContentPane(contentPane);
    frame.setSize(100, 100);
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    final ConfirmDialog dialog = new ConfirmDialog(f);
    final JTree tree = new JTree();
    tree.setVisibleRowCount(5);/*w  w  w. jav  a  2 s  .  c o m*/
    final JScrollPane treeScroll = new JScrollPane(tree);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton b = new JButton("Choose Tree Item");
    b.addActionListener(e -> {
        int result = dialog.showConfirmDialog(treeScroll, "Choose an item");
        if (result == ConfirmDialog.OK_OPTION) {
            System.out.println(tree.getSelectionPath());
        } else {
            System.out.println("User cancelled");
        }
    });
    JPanel p = new JPanel(new BorderLayout());
    p.add(b);
    p.setBorder(new EmptyBorder(50, 50, 50, 50));
    f.setContentPane(p);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    String[] data = { "alist", "arithmetic", "ASCIInumbers", "A", "B", "list", "C", "D", "E", "numeral", "G",
            "F" };

    JCheckBox[] checkBox;//ww  w  .  j  a v  a 2 s. c o  m
    JButton submitButton;
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    JPanel contentPane = new JPanel();
    contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(5, 5));

    checkBox = new JCheckBox[data.length];
    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new GridLayout(0, 4, 5, 5));
    for (int i = 0; i < data.length; i++) {
        checkBox[i] = new JCheckBox(data[i]);
        centerPanel.add(checkBox[i]);
    }
    contentPane.add(centerPanel, BorderLayout.CENTER);

    JPanel footerPanel = new JPanel();
    submitButton = new JButton("Submit");
    footerPanel.add(submitButton);
    contentPane.add(footerPanel, BorderLayout.PAGE_END);

    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}

From source file:edu.gmu.isa681.client.Main.java

public static void main(String[] args) {
    log.info("Setting look and feel...");

    try {//  w  w w . j  a v  a  2 s  .  co m
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }

    } catch (Exception ex1) {
        log.warn(ex1.getMessage(), ex1);
        log.warn("Nimbus is not available.");
        log.warn("Switching to system look and feel");
        log.warn("Some GUI discrepancies may occur!");

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ex2) {
            log.error(ex2.getMessage(), ex2);
            log.error("Could not setup a look and feel.");
            System.exit(1);
        }
    }

    log.info("Initializing GUI...");

    final JFrame frame = new JFrame();
    frame.setTitle("GoForward");
    frame.setBackground(new Color(0, 100, 0));
    UIManager.put("nimbusBase", new Color(0, 100, 0));
    //UIManager.put("nimbusBlueGrey", new Color(0, 100, 0));
    UIManager.put("control", new Color(0, 100, 0));

    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    frame.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            frame.setPreferredSize(frame.getSize());
        }
    });

    Dimension dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    if (dim.width < 1366) {
        frame.setPreferredSize(new Dimension(800, 600));
    } else {
        frame.setPreferredSize(new Dimension(1200, 700));
    }

    //frame.setResizable(false);
    frame.setLocationByPlatform(true);
    frame.pack();

    Client client = new Client("localhost", Constants.SERVER_PORT);
    Controller controller = new Controller(client, frame);
    controller.applicationStarted();

    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    log.info("Started");
}

From source file:Main.java

public static void main(String... args) {
    JPanel contentPane;//  w  ww.j a v a  2  s .  c  o m
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    contentPane = new JPanel();
    contentPane.setLayout(new GridBagLayout());

    JPanel centerPanel = new JPanel();
    centerPanel.setOpaque(true);
    centerPanel.setBackground(Color.CYAN);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.FIRST_LINE_START;
    gbc.weightx = 1.0;
    gbc.weighty = 0.9;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    gbc.fill = GridBagConstraints.BOTH;

    contentPane.add(centerPanel, gbc);

    JButton leftButton = new JButton("Left");
    JButton rightButton = new JButton("Right");
    gbc.gridwidth = 1;
    gbc.gridy = 1;
    gbc.weightx = 0.3;
    gbc.weighty = 0.1;

    contentPane.add(leftButton, gbc);

    gbc.gridx = 1;
    gbc.weightx = 0.7;
    gbc.weighty = 0.1;

    contentPane.add(rightButton, gbc);

    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}