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(String title) throws HeadlessException 

Source Link

Document

Creates a new, initially invisible Frame with the specified title.

Usage

From source file:DnDBetweenJTextAreaAndJTextFieldDemo.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Drag and Drop Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new JPanel());
    JTextField textField = new JTextField(25);
    textField.setText("www.java2s.com");
    frame.add(textField);// w  w  w. j a v  a2s  .c o m

    JTextArea textArea = new JTextArea(4, 25);
    textArea.setText("Demonstrating\ndrag and drop");
    frame.getContentPane().add(new JScrollPane(textArea));
    textArea.setDragEnabled(true);
    textField.setDragEnabled(true);
    frame.pack();
    frame.setVisible(true);

}

From source file:Main.java

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

    JList jlist = new JList(new String[] { "A", "B", "C" });

    jlist.setSelectedIndex(0);/*from w w w . ja v  a 2 s .  co  m*/
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1, BorderLayout.CENTER);

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

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList();
    jlist1.setListData(labels);//from w w  w  .j a  v  a 2s .com

    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    int mode = jlist1.getSelectionMode();

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

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList();
    jlist1.setListData(labels);/*from w  ww .ja  v a 2  s .  c  o m*/

    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    int i = jlist1.getAnchorSelectionIndex();

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

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList();
    jlist1.setListData(labels);/*from ww w .ja v a 2  s . c  o  m*/

    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    jlist1.getLeadSelectionIndex();

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

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList();
    jlist1.setListData(labels);/* ww  w . j  a v a2 s . c o m*/

    jlist1.setVisibleRowCount(4);
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    jlist1.setSelectedIndices(new int[] { 1, 2 });

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

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("SpringLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    // Set the content pane's layout to a SpringLayout
    SpringLayout springLayout = new SpringLayout();
    contentPane.setLayout(springLayout);

    // Add two JButtons to the content pane
    JButton b1 = new JButton("Button 1");
    JButton b2 = new JButton("Button Second");

    // Create Constraints objects for b1 and b2
    SpringLayout.Constraints b1c = new SpringLayout.Constraints();
    SpringLayout.Constraints b2c = new SpringLayout.Constraints();

    // Create a Spring object for y value for b1 and b2
    Spring yPadding = Spring.constant(20);

    // Set (10, 20) for (x, y) for b1
    b1c.setX(Spring.constant(10));
    b1c.setY(yPadding);/*  www .j a  v  a  2  s .c  om*/

    // Set (150, 20) for (x, y) for b2
    b2c.setX(Spring.constant(150));
    b2c.setY(yPadding);

    // Use the Constraints object while adding b1 and b2
    contentPane.add(b1, b1c);
    contentPane.add(b2, b2c);

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

From source file:MainClass.java

public static void main(final String args[]) {
    final String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Multi-Columns");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList columns = new JList(labels);
    columns.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    columns.setVisibleRowCount(3);/*from  w  w w .j  av a2s  .co m*/
    JScrollPane sp = new JScrollPane(columns);
    frame.add(sp, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

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

    JSlider jSliderOne = new JSlider();

    jSliderOne.setPaintLabels(true);/*from  w w w . j av  a 2s.  co m*/

    Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>();
    table.put(0, new JLabel(new ImageIcon("yourFile.gif")));
    table.put(10, new JLabel("Ten"));
    table.put(25, new JLabel("Twenty-Five"));
    table.put(34, new JLabel("Thirty-Four"));
    table.put(52, new JLabel("Fifty-Two"));
    table.put(70, new JLabel("Seventy"));
    table.put(82, new JLabel("Eighty-Two"));
    jSliderOne.setLabelTable(table);

    frame.add(jSliderOne, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:AnEmptyBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Empty Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border emptyBorder = BorderFactory.createEmptyBorder(20, 20, 0, 0);
    JButton emptyButton = new JButton("With Empty");
    emptyButton.setBorder(emptyBorder);/*from w w w .j  av  a 2s  .  c om*/
    JButton nonemptyButton = new JButton("Without Empty");
    Container contentPane = frame.getContentPane();
    contentPane.add(emptyButton, BorderLayout.NORTH);
    contentPane.add(nonemptyButton, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}