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) {
    EventQueue.invokeLater(new Runnable() {
        @Override//from  w ww . j  a va 2 s. c om
        public void run() {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new LoadImage());
            f.pack();
            f.setVisible(true);
        }
    });
}

From source file:Shear.java

public static void main(String[] args) {

    JFrame frame = new JFrame("Shearing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Shear());
    frame.setSize(330, 270);/*  www . jav a 2  s  .  co m*/
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextArea textArea = new JTextArea(5, 30);
    textArea.setOpaque(false);/*from   w  w  w.j  a  v  a  2s .com*/

    JViewport viewport = new JViewport() {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            int w = this.getWidth();
            int h = this.getHeight();
            g.setColor(Color.RED);
            g.fillRect(0, 0, w / 2, h / 2);
        }
    };

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewport(viewport);
    scrollPane.setViewportView(textArea);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(scrollPane);
    frame.setLocationByPlatform(true);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {
    JTree tree = new JTree();
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    int treeSelectedRows[] = { 3, 1 };
    tree.setSelectionRows(treeSelectedRows);
    TreeSelectionListener treeSelectionListener = new TreeSelectionListener() {

        @Override/*from  w ww  .  j  a v a2s.c om*/
        public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
            JTree treeSource = (JTree) treeSelectionEvent.getSource();
            System.out.println("Min: " + treeSource.getMinSelectionRow());
            System.out.println("Max: " + treeSource.getMaxSelectionRow());
            System.out.println("Lead: " + treeSource.getLeadSelectionRow());
            System.out.println("Row: " + treeSource.getSelectionRows()[0]);
        }
    };
    tree.addTreeSelectionListener(treeSelectionListener);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(tree));
    frame.setPreferredSize(new Dimension(380, 320));
    frame.setLocation(150, 150);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame("JTable");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.add(new Main());
    f.pack();/*w  w w  .  j  a  v  a 2 s .  co m*/
    f.setVisible(true);
}

From source file:TreeDISCONTIGUOUSSelection.java

public static void main(String[] argv) {
    JTree tree = new JTree();

    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

    JFrame frame = new JFrame("tree DISCONTIGUOUS selection");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(tree));
    frame.setSize(380, 320);//from w  ww. ja  va2s.  c  om
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    String[] mainData = { "-Select-", "Sel 1", "Sel 2", "Sel 3" };
    String[] subData1 = { "Sub Sel 11", "Sub Sel 12", "Sub Sel 13" };
    String[] subData2 = { "Sub Sel 21", "Sub Sel 22", "Sub Sel 23" };
    String[] subData3 = { "Sub Sel 31", "Sub Sel 32", "Sub Sel 33" };
    DefaultComboBoxModel boxModel = new DefaultComboBoxModel();
    JComboBox box1 = new JComboBox(mainData), box2 = new JComboBox();
    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.add(box1);
    frame.add(box2);// w  w w.  java2 s  .c  om
    box2.setVisible(false);
    box2.setModel(boxModel);
    frame.setBounds(200, 200, 500, 200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    box1.addItemListener(e -> {
        box2.setVisible(true);
        boxModel.removeAllElements();
        if (box1.getSelectedIndex() == 0) {
            box2.setVisible(false);
        } else if (box1.getSelectedIndex() == 1) {
            for (String s : subData1) {
                boxModel.addElement(s);
            }
        } else if (box1.getSelectedIndex() == 2) {
            for (String s : subData2) {
                boxModel.addElement(s);
            }
        } else if (box1.getSelectedIndex() == 3) {
            for (String s : subData3) {
                boxModel.addElement(s);
            }
        }
    });
}

From source file:Main.java

License:asdf

public static void main(String[] args) {

    JFrame frame = new JFrame("Basic Shapes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Main());
    frame.setSize(350, 250);//from   w ww . j a v  a2  s . c  o m
    frame.setLocationRelativeTo(null);
    frame.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);//from w  w w.  j a v  a  2s.  c  o m
    f.setVisible(true);
}

From source file:InvokeLaterExample.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(1);//ww  w  . jav  a 2  s.  co  m
    f.add(new InvokeLaterExample());
    f.pack();
    f.setVisible(true);
}