Example usage for javax.swing JFrame setSize

List of usage examples for javax.swing JFrame setSize

Introduction

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

Prototype

public void setSize(int width, int height) 

Source Link

Document

The width and 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) {
    JFrame frame = new JFrame();
    JButton button = new JButton("Start Animation");
    button.addActionListener(new Main(frame));
    frame.getContentPane().add(button);//from w  w w .  j  av a 2  s. com
    frame.setSize(300, 300);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] args) {
    JTextArea ta = new JTextArea();
    ta.setLineWrap(true);/*from   www. j  a  v  a  2 s  .c om*/
    ta.setWrapStyleWord(true);
    JScrollPane scroll = new JScrollPane(ta);

    ta.append("www.\n");
    ta.append("java2s\n");
    ta.append(".com");

    try {
        for (int n = 0; n < ta.getLineCount(); n += 1)
            System.out.println("line " + n + " starts at " + ta.getLineStartOffset(n) + ", ends at "
                    + ta.getLineEndOffset(n));
        System.out.println();

        int n = 0;
        while (true) {
            System.out.print("offset " + n + " is on ");
            System.out.println("line " + ta.getLineOfOffset(n));
            n += 1;
        }
    } catch (BadLocationException ex) {
        System.out.println(ex);
    }

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(scroll, java.awt.BorderLayout.CENTER);
    f.setSize(150, 150);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextField tf = new JTextField("mm");
    tf.setPreferredSize(tf.getPreferredSize());
    tf.setText("");

    JPanel pHacked = new JPanel();
    pHacked.add(tf);//from  w w  w.  j  av  a  2s  .  c om

    JPanel pStock = new JPanel();
    pStock.add(new JTextField(2));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new java.awt.GridLayout(0, 1));
    frame.add(pHacked);
    frame.add(pStock);
    frame.setSize(150, 150);
    frame.setVisible(true);
    tf.requestFocus();
}

From source file:Main.java

public static void main(String[] args) {
    BoundedRangeModel model = new DefaultBoundedRangeModel();
    BlockedColorLayerUI layerUI = new BlockedColorLayerUI();
    JPanel p = new JPanel(new GridLayout(2, 1, 12, 12));

    p.add(new JLayer<JProgressBar>(new JProgressBar(model), layerUI));

    JPanel box = new JPanel();
    box.add(new JButton(new AbstractAction("+10") {
        private int i = 0;

        @Override/*from w  w w .ja  va  2 s. co m*/
        public void actionPerformed(ActionEvent e) {
            model.setValue(i = (i >= 100) ? 0 : i + 10);
        }
    }));

    p.repaint();

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(p, BorderLayout.NORTH);
    panel.add(box, BorderLayout.SOUTH);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(panel);
    f.setSize(320, 240);
    f.setVisible(true);
}

From source file:org.eclipse.swt.snippets.Snippet337.java

public static void main(String args[]) {
    display = new Display();
    EventQueue.invokeLater(() -> {
        JFrame mainFrame = new JFrame("Main Window");
        mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        mainFrame.addWindowListener(new Snippet337.CloseListener());
        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new FlowLayout());
        JButton launchBrowserButton = new JButton("Launch Browser");
        launchBrowserButton.addActionListener(e -> {
            JFrame childFrame = new JFrame();
            final Canvas canvas = new Canvas();
            childFrame.setSize(850, 650);
            childFrame.getContentPane().add(canvas);
            childFrame.setVisible(true);
            display.asyncExec(() -> {
                Shell shell = SWT_AWT.new_Shell(display, canvas);
                shell.setSize(800, 600);
                Browser browser = new Browser(shell, SWT.NONE);
                browser.setLayoutData(new GridData(GridData.FILL_BOTH));
                browser.setSize(800, 600);
                browser.setUrl("http://www.eclipse.org");
                shell.open();//from  ww w.j  a va2 s . c  o  m
            });
        });

        mainPanel.add(new JTextField("a JTextField"));
        mainPanel.add(launchBrowserButton);
        mainFrame.getContentPane().add(mainPanel, BorderLayout.CENTER);
        mainFrame.pack();
        mainFrame.setVisible(true);
    });
    display.addListener(SWT.Close, event -> EventQueue.invokeLater(() -> {
        Frame[] frames = Frame.getFrames();
        for (int i = 0; i < frames.length; i++) {
            frames[i].dispose();
        }
    }));
    while (!display.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

From source file:ButtonTipTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tool Tips");
    Container contentPane = frame.getContentPane();
    JButton b = new JButton("Button");
    b.setToolTipText("Go Away");
    contentPane.add(b, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.show();//  w w w . j a va  2s .  com
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();

    ImageIcon ii = new ImageIcon("largeJava2sLogo.gif");
    JScrollPane jsp = new JScrollPane(new ScrollableLabel(ii));
    f.getContentPane().add(jsp);/*from w w w.  ja v  a 2s  .co  m*/
    f.setSize(300, 250);
    f.setVisible(true);

}

From source file:lu.lippmann.cdb.common.gui.MultiPanel.java

public static final void main(String[] args) {
    int w = 1024, h = 768;

    JPanel panel1 = new JPanel();
    panel1.setToolTipText("Panel 1");
    JPanel panel2 = new JPanel();
    panel2.setToolTipText("Panel 2");
    JPanel panel3 = new JPanel();
    panel3.setToolTipText("Panel 3");
    JPanel panel4 = new JPanel();
    panel4.setToolTipText("Panel 4");
    JPanel panel5 = new JPanel();
    panel5.setToolTipText("Panel 5");

    final ListOrderedMap<JComponent, Integer> mapPanels = new ListOrderedMap<JComponent, Integer>();

    //add in increasing order or in the order you want to maintain ...
    mapPanels.put(panel4, 5);/* ww  w . ja  va2  s . c  o  m*/
    mapPanels.put(panel5, 5);
    mapPanels.put(panel3, 10);
    mapPanels.put(panel1, 30);
    mapPanels.put(panel2, 50);

    MultiPanel mp = new MultiPanel(mapPanels, w, h, false);
    JFrame f = new JFrame("MultiPanel test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(w, h);
    f.getContentPane().add(mp);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String s[]) {
    JFrame frame = new JFrame("Popup Menu Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new Main());
    frame.setSize(300, 300);
    frame.setVisible(true);//from  ww w.jav a  2  s .c  o m
}

From source file:Main.java

public static void main(String args[]) {
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);
    JTextField textField = new JTextField();
    label.setLabelFor(textField);/*from  w  ww .  j a  v a2 s .  com*/
    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(panel, BorderLayout.NORTH);
    frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);
}