Example usage for javax.swing JFrame JFrame

List of usage examples for javax.swing JFrame JFrame

Introduction

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

Prototype

public JFrame() throws HeadlessException 

Source Link

Document

Constructs a new frame that is initially invisible.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame jf = new JFrame();
    Container cp = jf.getContentPane();
    MyCanvas tl = new MyCanvas();
    cp.add(tl);//from w ww.j a  v a 2  s.c o  m
    jf.setSize(300, 200);
    jf.setVisible(true);
}

From source file:RegisterChangeListenerToJSlider.java

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

    JSlider framesPerSecond = new JSlider(JSlider.HORIZONTAL, 10, 100, 20);
    framesPerSecond.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                int fps = (int) source.getValue();
                System.out.println(fps);
            }/*from www  .j  a v  a 2s. c o  m*/
        }
    });

    frame.add(framesPerSecond, "North");

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Box rowOne = Box.createHorizontalBox();
    rowOne.add(new JLabel("Username"));
    rowOne.add(new JTextField());
    Box rowTwo = Box.createHorizontalBox();
    rowTwo.add(new JLabel("Password"));
    rowTwo.add(new JPasswordField());
    f.add(rowOne, BorderLayout.NORTH);
    f.add(rowTwo, BorderLayout.SOUTH);
    f.setSize(300, 200);/*from   w  w w  . j  a  v a  2s.  com*/
    f.setVisible(true);
}

From source file:Main.java

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

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode mercury = new DefaultMutableTreeNode("Mercury");
    root.insert(mercury, 0);//from ww w.  ja  v a  2  s  .  c o m
    DefaultMutableTreeNode venus = new DefaultMutableTreeNode("Venus");
    root.insert(venus, 1);
    DefaultMutableTreeNode mars = new DefaultMutableTreeNode("Mars");
    root.insert(mars, 2);
    JTree tree = new JTree(root);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:GridBagLayoutRemainder.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = f.getContentPane();
    pane.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    pane.add(new JButton("First row, first column"), gbc);
    pane.add(new JButton("First row, second column"), gbc);
    pane.add(new JButton("First row, third column"), gbc);
    gbc.gridx = 0;//from  ww  w .  j  a  va2s  .  c  o  m
    pane.add(new JButton("Second row"), gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    pane.add(new JButton("Third row, gridwidth set to REMAINDER"), gbc);
    f.setSize(600, 300);
    f.setVisible(true);
}

From source file:Main.java

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

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new GridLayout(1, 2, 2, 2));

    JTextArea tArea1 = new JTextArea();
    tArea1.setLineWrap(true);//w ww. j ava2 s . co  m
    JTextArea tArea2 = new JTextArea();
    tArea2.setLineWrap(true);
    tArea1.setText("I got a long long line of text in my JTextArea");
    tArea2.setText("I got a long long line of text in my JTextArea");

    JScrollPane scroller1 = new JScrollPane();
    JScrollPane scroller2 = new JScrollPane();
    scroller1.setViewportView(tArea1);
    scroller2.setViewportView(tArea2);

    contentPane.add(scroller1);
    contentPane.add(scroller2);

    frame.setContentPane(contentPane);
    frame.setSize(100, 100);
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}

From source file:Main.java

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

    Vector<String> rowOne = new Vector<String>();
    rowOne.addElement("Row1-Column1");
    rowOne.addElement("Row1-Column2");
    rowOne.addElement("Row1-Column3");

    Vector<String> rowTwo = new Vector<String>();
    rowTwo.addElement("Row2-Column1");
    rowTwo.addElement("Row2-Column2");
    rowTwo.addElement("Row2-Column3");

    Vector<Vector> rowData = new Vector<Vector>();
    rowData.addElement(rowOne);/*from   w  ww. ja v  a 2s.  co m*/
    rowData.addElement(rowTwo);

    Vector<String> columnNames = new Vector<String>();
    columnNames.addElement("Column One");
    columnNames.addElement("Column Two");
    columnNames.addElement("Column Three");
    JTable table = new JTable(rowData, columnNames);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:Main.java

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

    JDesktopPane desktop = new JDesktopPane();
    JInternalFrame internalFrame = new JInternalFrame("Can Do All", true, true, true, true);

    desktop.add(internalFrame);/*from   w w  w  . j av  a  2 s  .c  o m*/

    internalFrame.setBounds(25, 25, 200, 100);

    JLabel label = new JLabel(internalFrame.getTitle(), JLabel.CENTER);
    internalFrame.add(label, BorderLayout.CENTER);

    internalFrame.setVisible(true);

    desktop.getDesktopManager().maximizeFrame(internalFrame);

    frame.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");
    System.out.println(jb.getMnemonic());

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);/*from   www  . j  av a 2s  .  c  om*/
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

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

    ImageIcon icon = new ImageIcon("yourFile.gif");

    Image normalImage = icon.getImage();
    Image grayImage = GrayFilter.createDisabledImage(normalImage);
    Icon warningIcon = new ImageIcon(grayImage);
    JLabel warningLabel = new JLabel(warningIcon);

    JLabel label3 = new JLabel("Warning", icon, JLabel.CENTER);

    frame.add(warningLabel, "Center");
    frame.add(label3, "South");

    frame.setSize(300, 200);// w ww  .  j  a v  a  2s  .co  m
    frame.setVisible(true);
}