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: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);//from   w w w  .  jav  a2 s  .  c  o  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:DragDropList.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.add(new JScrollPane(new DragDropList()));
    f.setSize(300, 300);
    f.setVisible(true);//w w w .  ja  v  a 2 s  . c om
}

From source file:Main.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override// w  w w  .  j ava2 s  .  co m
        public void run() {
            JFrame frame = new JFrame();
            frame.add(new ImagePanel());

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(400, 400);
            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 ww  .j a v  a 2 s.co  m
        }
    };

    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);

}

From source file:BoundedChangeListener.java

public static void main(String args[]) {
    ChangeListener changeListener = new BoundedChangeListener();
    JScrollBar aJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
    BoundedRangeModel model = aJScrollBar.getModel();
    model.addChangeListener(changeListener);

    JFrame frame = new JFrame("ScrollBars R Us");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(aJScrollBar, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);//w w  w . jav a  2 s .c  o  m
}

From source file:MainClass.java

public static void main(String s[]) {
    JFrame frame = new JFrame("Custom Curved Border");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 150);
    frame.setContentPane(new MainClass());
    frame.setVisible(true);/*from   w  w w.j a  v  a  2s .com*/
}

From source file:TextLayoutWithCarets.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.getContentPane().add(new TextLayoutWithCarets());
    f.setSize(350, 250);
    f.setVisible(true);//from   w w  w.  j a  v a2s.  c o m

}

From source file:Main.java

public static void main(String[] argv) {
    JTextComponent textcomp = new JTextArea();
    final UndoManager undo = new UndoManager();
    Document doc = textcomp.getDocument();

    doc.addUndoableEditListener(new UndoableEditListener() {
        public void undoableEditHappened(UndoableEditEvent evt) {
            undo.addEdit(evt.getEdit());
        }/*from   w  w  w  .j  a  v a2 s. c  o m*/
    });

    textcomp.getActionMap().put("Undo", new AbstractAction("Undo") {
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undo.canUndo()) {
                    undo.undo();
                }
            } catch (CannotUndoException e) {
            }
        }
    });

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(textcomp));
    frame.setSize(380, 320);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new JTabbedPaneDemo());
    f.setSize(500, 500);
    f.setVisible(true);/*from   w w  w  .  jav a  2  s. c  o m*/
}

From source file:CurvedExample.java

public static void main(String s[]) {
    JFrame frame = new JFrame("Custom Curved Border");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 150);
    frame.setContentPane(new CurvedExample());
    frame.setVisible(true);//  ww w  .j av  a2  s .c om
}