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) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new MyContentPane());
    frame.pack();/*from   w  w w  .j a  v  a 2  s  .c om*/
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JPanel ui = new JPanel(new BorderLayout(2, 2));
    ui.setBorder(new EmptyBorder(4, 4, 4, 4));

    JPanel controls = new JPanel(new BorderLayout(2, 2));
    ui.add(controls, BorderLayout.PAGE_START);
    String s = new String(Character.toChars(8594));
    String[] items = { "Choice: right " + s + " arrow" };
    JComboBox cb = new JComboBox(items);
    controls.add(cb, BorderLayout.CENTER);
    controls.add(new JButton("Button"), BorderLayout.LINE_END);

    JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JTextArea(4, 40), new JTextArea(4, 40));

    ui.add(sp, BorderLayout.CENTER);

    JFrame f = new JFrame("Stretch Combo Layout");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setContentPane(ui);//  w  w w  . ja  va  2s  .com
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JPanel bottomPanel = new JPanel();
    bottomPanel.add(new JButton("Bottom Button"));
    bottomPanel.setBorder(BorderFactory.createTitledBorder("Bottom Panel"));

    JPanel centerPanel = new JPanel();
    centerPanel.setBorder(BorderFactory.createTitledBorder("Center Panel"));

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(centerPanel, BorderLayout.CENTER);
    mainPanel.add(bottomPanel, BorderLayout.PAGE_END);

    int eb = 25;//from w  ww . j a va2 s  . com
    mainPanel.setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));

    mainPanel.setPreferredSize(new Dimension(500, 400));

    JFrame frame = new JFrame("Main");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(mainPanel);
    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Main mainPanel = new Main();

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(mainPanel);
    frame.pack();// w  w w.j  a  v  a  2 s .co  m
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Main mainPanel = new Main();

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(mainPanel);/*w w w .  j  a v a 2 s . c o m*/
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    Main mainPanel = new Main();

    JFrame frame = new JFrame("CalcEg");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(mainPanel.getMainComponent());
    frame.pack();/*w ww.j a  v a2s. c  o m*/
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JButton close = new JButton("Close me programmatically");
    final JFrame f = new JFrame("Close Me");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(close);/* w w w.ja va  2 s  . c om*/
    close.addActionListener(e -> {
        f.dispose();
    });
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    int result = JOptionPane.showConfirmDialog(null, "Show over parent?");
    for (int i = 1; i < 4; i++) {
        JFrame f = new JFrame("Frame " + i);
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        Component parent = (JOptionPane.OK_OPTION == result ? f : null);

        f.setSize(400, 300);/*www .  j a v  a 2s  . com*/
        f.setLocationByPlatform(true);
        f.setVisible(true);

        JDialog d = new JDialog(f);
        d.setTitle("Dialog " + i);
        d.setSize(300, 200);
        d.setLocationRelativeTo(parent);
        d.setVisible(true);
    }
}

From source file:Main.java

public static void main(String[] args) {
    JPanel ui = new JPanel(new BorderLayout(4, 4));
    ui.setBorder(new EmptyBorder(6, 6, 6, 6));

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.LEADING));
    ui.add(controls, BorderLayout.PAGE_START);
    int s = 100;//from   w  w w .  ja va 2 s . c  om
    Dimension[] sizes = { new Dimension(s * 4, s * 2), new Dimension(s * 6, s * 3),
            new Dimension(s * 8, s * 4) };
    final JComboBox cb = new JComboBox(sizes);
    controls.add(cb);
    final JPanel[] panels = new JPanel[sizes.length];
    for (int ii = 0; ii < sizes.length; ii++) {
        Dimension d = sizes[ii];
        BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
        JPanel p = new JPanel(new GridLayout());
        JLabel l = new JLabel(new ImageIcon(bi));
        p.add(l);
        panels[ii] = p;
    }
    ItemListener sizeListener = new ItemListener() {

        JPanel current = panels[0];

        @Override
        public void itemStateChanged(ItemEvent e) {
            JPanel next = panels[cb.getSelectedIndex()];
            swapComponentsAndResizeUI(ui, current, next);
            current = next;
        }
    };
    cb.addItemListener(sizeListener);

    ui.add(panels[0], BorderLayout.CENTER);

    JFrame f = new JFrame("Three Sized Panels");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setContentPane(ui);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    DrawPanel dp = new DrawPanel();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(dp);/*from w w  w  .j av a 2  s .  com*/
    frame.pack();
    frame.setLocationByPlatform(true);
    try {
        Sequence seq = new Sequence(Sequence.PPQ, 4);
        Track track = seq.createTrack();
        for (int i = 0; i < 120; i += 4) {
            int d = (int) Math.abs(new Random().nextGaussian() * 24) + 32;
            track.add(makeEvent(ShortMessage.NOTE_ON, 1, d, 127, i));
            track.add(makeEvent(ShortMessage.CONTROL_CHANGE, 1, 127, 0, i));
            track.add(makeEvent(ShortMessage.NOTE_OFF, 1, d, 127, i));
        }
        Sequencer sequencer = MidiSystem.getSequencer();
        sequencer.open();
        sequencer.setSequence(seq);
        sequencer.addControllerEventListener(dp, new int[] { 127 });
        sequencer.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
    frame.setVisible(true);
}