Example usage for javax.swing JFrame add

List of usage examples for javax.swing JFrame add

Introduction

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

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    final JFrame frame = new JFrame();
    frame.setUndecorated(true);/* w ww. j a v  a2  s . c o m*/
    JButton button = new JButton("Minimize");
    button.addActionListener(e -> frame.setState(Frame.ICONIFIED));
    frame.add(button);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}

From source file:MyActionListener.java

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

    JButton button = new JButton("Click and holding alt, control, and shift key");
    button.addActionListener(new MyActionListener());
    frame.add(button);
    frame.pack();/*from w  w  w .j a  va2  s . com*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);//w w w . j  a  v a 2  s  .c o m
    format.setMinimumFractionDigits(2);
    format.setParseIntegerOnly(true);
    format.setRoundingMode(RoundingMode.HALF_UP);

    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setMaximum(1000);
    formatter.setMinimum(0.0);
    formatter.setAllowsInvalid(false);
    // formatter.setOverwriteMode(false);

    JFormattedTextField tf = new JFormattedTextField(formatter);
    tf.setColumns(10);
    tf.setValue(123456789.99);
    JFormattedTextField tf1 = new JFormattedTextField(formatter);
    tf1.setValue(1234567890.99);
    JFormattedTextField tf2 = new JFormattedTextField(formatter);
    tf2.setValue(1111.1111);
    JFormattedTextField tf3 = new JFormattedTextField(formatter);
    tf3.setValue(-1111.1111);
    JFormattedTextField tf4 = new JFormattedTextField(formatter);
    tf4.setValue(-56);

    JFrame frame = new JFrame("Test");
    frame.setLayout(new GridLayout(5, 0));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(tf);
    frame.add(tf1);
    frame.add(tf2);
    frame.add(tf3);
    frame.add(tf4);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button1 = new JButton("Text Button");
    button1.setMnemonic(KeyEvent.VK_B);
    frame.add(button1);
    frame.setSize(300, 200);/*from   ww w . j a  va2 s .  c o  m*/
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(new JButton("A"));

    frame.add(buttonPanel);

    frame.setSize(300, 200);//w  w  w.j  av a 2  s .  c  o  m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Vector<Double> doubleVector = new Vector<Double>();
    Vector<Integer> integerVector = new Vector<Integer>();
    Vector<Boolean> booleanVector = new Vector<Boolean>();
    Vector<Icon> iconVector = new Vector<Icon>();
    Icon icon1 = ((UIManager.getIcon("OptionPane.errorIcon")));
    Icon icon2 = (UIManager.getIcon("OptionPane.informationIcon"));
    Icon icon3 = (UIManager.getIcon("OptionPane.warningIcon"));
    Icon icon4 = (UIManager.getIcon("OptionPane.questionIcon"));

    doubleVector.addElement(1.001);/* w ww  .  j a  v a 2  s  .co  m*/
    doubleVector.addElement(10.00);
    doubleVector.addElement(0.95);
    doubleVector.addElement(4.2);
    JComboBox comboBoxDouble = new JComboBox(doubleVector);
    integerVector.addElement(1);
    integerVector.addElement(2);
    integerVector.addElement(3);
    integerVector.addElement(4);
    JComboBox comboBoxInteger = new JComboBox(integerVector);
    booleanVector.add(Boolean.TRUE);
    booleanVector.add(Boolean.FALSE);
    JComboBox comboBoxBoolean = new JComboBox(booleanVector);
    iconVector.addElement(icon1);
    iconVector.addElement(icon2);
    iconVector.addElement(icon3);
    iconVector.addElement(icon4);
    JComboBox comboBoxIcon = new JComboBox(iconVector);
    JFrame frame = new JFrame();
    frame.setLayout(new GridLayout(2, 2, 5, 5));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(comboBoxDouble);
    frame.add(comboBoxInteger);
    frame.add(comboBoxBoolean);
    frame.add(comboBoxIcon);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame();
    GridBagLayout gbl = new GridBagLayout();

    frame.setLayout(gbl);/*from  ww w.  ja v a 2  s. com*/
    JButton component = new JButton("1");

    frame.add(new JButton("2"));
    frame.add(new JButton("3"));
    frame.add(new JButton("4"));
    frame.add(new JButton("5"));
    frame.add(component);
    frame.add(new JButton("6"));
    frame.add(new JButton("7"));
    frame.add(new JButton("8"));
    frame.add(new JButton("9"));
    frame.add(new JButton("0"));

    gbl.layoutContainer(frame);

    GridBagConstraints gbc = new GridBagConstraints();

    int top = 20;
    int left = 20;
    int bottom = 2;
    int right = 40;
    gbc.insets = new Insets(top, left, bottom, right);

    gbl.setConstraints(component, gbc);

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

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

    JSeparator sep = new JSeparator(JSeparator.VERTICAL);
    sep.setOrientation(JSeparator.VERTICAL);
    frame.add(sep);

    frame.setSize(300, 200);/*from w  w w. java 2  s.  c  o m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JSeparator Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLayout(new GridLayout(0, 1));
    JLabel above = new JLabel("Above Separator");
    f.add(above);
    JSeparator separator = new JSeparator();
    f.add(separator);/*from   w ww .  ja  v  a 2 s.  c  om*/
    JLabel below = new JLabel("Below Separator");
    f.add(below);
    f.setSize(300, 100);
    f.setVisible(true);
}

From source file:MyComponent.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame();
    aWindow.setBounds(30, 30, 300, 300); // Size
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    MyComponent com = new MyComponent();

    aWindow.add(com);

    aWindow.setVisible(true); // Display the window
}