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[]) {
    JPanel p = new JPanel();

    p.setLayout(new GridLayout(2, 1));
    JList<String> lista = new JList<>(new String[] { "1", "2", "3", "4" });
    p.add(new JScrollPane(lista));
    JComboBox<String> combo = new JComboBox<>();
    for (int i = 0; i < 100; i++) {
        combo.addItem(Integer.toString(i));
        p.add(combo);// w w  w  .  j  a va  2 s . c om
    }

    JFrame f = new JFrame();
    f.getContentPane().add(p, BorderLayout.CENTER);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(200, 200);
    f.setVisible(true);
}

From source file:JTableSortDemo.java

public static void main(String[] args) {
    Object[][] data = { { "A", 5 }, { "B", 2 }, { "C", 4 }, { "D", 8 } };
    String columnNames[] = { "Item", "Value" };
    TableModel model = new DefaultTableModel(data, columnNames) {
        public Class<?> getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }//from ww  w .j ava  2 s  . c  o  m
    };
    JTable table = new JTable(model);

    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);

    JScrollPane scrollPane = new JScrollPane(table);
    JFrame frame = new JFrame("Sorting Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(scrollPane);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String[] headers = { "column 1", "column 2", "column 3", "column 4" };
    int cols = 4;
    int rows = 6;
    String[][] data = new String[rows][cols];
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            data[row][col] = "item " + (row * cols + col + 1);
        }/*from  w w  w  . j a v  a2  s  . com*/
    }
    JTable table = new JTable(data, headers);
    DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) table.getDefaultRenderer(String.class);
    renderer.setHorizontalAlignment(JLabel.RIGHT);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(table));
    f.setSize(400, 400);
    f.setLocation(200, 200);
    f.setVisible(true);
}

From source file:Main.java

static public void main(String args[]) throws Exception {
    JFrame frame = new JFrame("ShowImageIR.java");
    Panel panel = new Main(args[0]);
    frame.getContentPane().add(panel);//  ww  w.ja va  2  s  .c  om
    frame.setSize(400, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new Main());

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);
    frame.setVisible(true);// w ww.  j  a  v  a  2 s .c om
}

From source file:MainClass.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Spring Layout");
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setSize(500, 500);
    SpringLayout layout = new SpringLayout();
    Container content = aWindow.getContentPane();
    content.setLayout(layout);/*  w w  w . j av  a 2  s .c om*/

    JButton[] buttons = new JButton[6];
    SpringLayout.Constraints constr = null;
    for (int i = 0; i < buttons.length; i++) {
        buttons[i] = new JButton("Press " + (i + 1));
        content.add(buttons[i]);
    }

    Spring xSpring = Spring.constant(5, 15, 25);
    Spring ySpring = Spring.constant(10, 30, 50);

    constr = layout.getConstraints(buttons[0]);
    constr.setX(xSpring);
    constr.setY(ySpring);

    for (int i = 1; i < buttons.length; i++) {
        constr = layout.getConstraints(buttons[i]);
        layout.putConstraint(SpringLayout.WEST, buttons[i], xSpring, SpringLayout.EAST, buttons[i - 1]);
        layout.putConstraint(SpringLayout.NORTH, buttons[i], ySpring, SpringLayout.SOUTH, buttons[i - 1]);
    }
    aWindow.setVisible(true); // Display the window
}

From source file:CompositingDST.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Composition");
    frame.add(new CompositingDST());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 120);
    frame.setVisible(true);//from w  w  w.jav  a  2  s.c o m
}

From source file:Main.java

public static void main(String[] args) throws MidiUnavailableException {
    // We don't need a Sequencer in this example, since we send MIDI
    // events directly to the Synthesizer instead.
    Synthesizer synthesizer = MidiSystem.getSynthesizer();
    synthesizer.open();/*  www  .  j av a  2s .  c o m*/
    JFrame frame = new Main(synthesizer);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(50, 128); // We use window width as volume control
    frame.setVisible(true);
}

From source file:Drums.java

public static void main(String[] args) throws MidiUnavailableException {
    // We don't need a Sequencer in this example, since we send MIDI
    // events directly to the Synthesizer instead.
    Synthesizer synthesizer = MidiSystem.getSynthesizer();
    synthesizer.open();/*from   w  w w.j ava2  s . c  o  m*/
    JFrame frame = new Drums(synthesizer);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(50, 128); // We use window width as volume control
    frame.setVisible(true);
}

From source file:GettingFontMetrics.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    FontMetrics metrics = f.getFontMetrics(f.getFont());

    f.setSize(300, 200);
    f.setVisible(true);/*  w w w  .jav a 2s . com*/
}