List of usage examples for javax.swing JFrame setContentPane
@BeanProperty(bound = false, hidden = true, description = "The client area of the frame where child components are normally inserted.") public void setContentPane(Container contentPane)
contentPane
property. From source file:DnDDemo3.java
public static void main(String[] args) { JPanel north = new JPanel(); north.add(new JLabel("Drag from here:")); JTextField field = new JTextField(10); field.setDragEnabled(true);/* w w w. j a va2 s. c o m*/ north.add(field); final DefaultListModel listModel = new DefaultListModel(); listModel.addElement("first"); listModel.addElement("second"); final JList list = new JList(listModel); list.setDragEnabled(true); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() == -1) { return false; } else { return true; } } public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } Transferable transferable = support.getTransferable(); String data; try { data = (String) transferable.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { listModel.add(index, data); } else { listModel.set(index, data); } Rectangle r = list.getCellBounds(index, index); list.scrollRectToVisible(r); return true; } }); JScrollPane center = new JScrollPane(); center.setViewportView(list); list.setDropMode(DropMode.USE_SELECTION); JPanel cp = new JPanel(); cp.setLayout(new BorderLayout()); cp.add(north, BorderLayout.NORTH); cp.add(center, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String s[]) { JFrame frame = new JFrame("Custom Curved Border"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 150);/*from w ww .ja va 2s. c o m*/ frame.setContentPane(new MainClass()); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextArea textArea = new JTextArea(10, 20); final JProgressBar progressBar = new JProgressBar(0, 10); final CounterTask task = new CounterTask(); task.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if ("progress".equals(evt.getPropertyName())) { progressBar.setValue((Integer) evt.getNewValue()); }/* w ww. j a v a2 s .c o m*/ } }); JButton startButton = new JButton("Start"); startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { task.execute(); } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { task.cancel(true); } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(startButton); buttonPanel.add(cancelButton); JPanel cp = new JPanel(); LayoutManager layout = new BoxLayout(cp, BoxLayout.Y_AXIS); cp.setLayout(layout); cp.add(buttonPanel); cp.add(new JScrollPane(textArea)); cp.add(progressBar); JFrame frame = new JFrame("SwingWorker Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }
From source file:CurvedExample.java
public static void main(String s[]) { JFrame frame = new JFrame("Custom Curved Border"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 150);/*from w ww . j a va2s. c o m*/ frame.setContentPane(new CurvedExample()); frame.setVisible(true); }
From source file:BorderLayoutPane.java
public static void main(String[] a) { JFrame f = new JFrame(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/*from ww w. jav a 2 s. c o m*/ } }); f.setContentPane(new BorderLayoutPane()); f.pack(); f.setVisible(true); }
From source file:aurelienribon.gdxsetupui.ui.Main.java
public static void main(String[] args) { parseArgs(args);/*from w w w. ja va2 s .c o m*/ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException ex) { } catch (InstantiationException ex) { } catch (IllegalAccessException ex) { } catch (UnsupportedLookAndFeelException ex) { } SwingStyle.init(); ArStyle.init(); JFrame frame = new JFrame("LibGDX Project Setup (gdx-setup-ui)"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new MainPanel()); frame.setSize(1100, 600); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); }
From source file:DropModeON.java
public static void main(String[] args) { JPanel north = new JPanel(); north.add(new JLabel("Drag from here:")); JTextField field = new JTextField(10); field.setDragEnabled(true);/*from www . j a v a2 s . c o m*/ north.add(field); final DefaultListModel listModel = new DefaultListModel(); listModel.addElement("first"); listModel.addElement("second"); final JList list = new JList(listModel); list.setDragEnabled(true); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() == -1) { return false; } else { return true; } } public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } Transferable transferable = support.getTransferable(); String data; try { data = (String) transferable.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { listModel.add(index, data); } else { listModel.set(index, data); } // Scroll to display the element that was dropped Rectangle r = list.getCellBounds(index, index); list.scrollRectToVisible(r); return true; } }); JScrollPane center = new JScrollPane(); center.setViewportView(list); list.setDropMode(DropMode.ON); JPanel cp = new JPanel(); cp.setLayout(new BorderLayout()); cp.add(north, BorderLayout.NORTH); cp.add(center, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }
From source file:DropModeON_OR_INSERT.java
public static void main(String[] args) { JPanel north = new JPanel(); north.add(new JLabel("Drag from here:")); JTextField field = new JTextField(10); field.setDragEnabled(true);//from w w w . j ava2 s .co m north.add(field); final DefaultListModel listModel = new DefaultListModel(); listModel.addElement("first"); listModel.addElement("second"); final JList list = new JList(listModel); list.setDragEnabled(true); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() == -1) { return false; } else { return true; } } public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } Transferable transferable = support.getTransferable(); String data; try { data = (String) transferable.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { listModel.add(index, data); } else { listModel.set(index, data); } // Scroll to display the element that was dropped Rectangle r = list.getCellBounds(index, index); list.scrollRectToVisible(r); return true; } }); JScrollPane center = new JScrollPane(); center.setViewportView(list); list.setDropMode(DropMode.ON_OR_INSERT); JPanel cp = new JPanel(); cp.setLayout(new BorderLayout()); cp.add(north, BorderLayout.NORTH); cp.add(center, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }
From source file:SimpleFTF.java
public static void main(String argv[]) { if (argv.length > 0) { // change to command-line locale if (argv[0].equalsIgnoreCase("canada")) java.util.Locale.setDefault(java.util.Locale.CANADA); if (argv[0].equalsIgnoreCase("canada_french")) java.util.Locale.setDefault(java.util.Locale.CANADA_FRENCH); if (argv[0].equalsIgnoreCase("china")) java.util.Locale.setDefault(java.util.Locale.CHINA); if (argv[0].equalsIgnoreCase("france")) java.util.Locale.setDefault(java.util.Locale.FRANCE); if (argv[0].equalsIgnoreCase("germany")) java.util.Locale.setDefault(java.util.Locale.GERMANY); if (argv[0].equalsIgnoreCase("italy")) java.util.Locale.setDefault(java.util.Locale.ITALY); if (argv[0].equalsIgnoreCase("japan")) java.util.Locale.setDefault(java.util.Locale.JAPAN); if (argv[0].equalsIgnoreCase("korea")) java.util.Locale.setDefault(java.util.Locale.KOREA); if (argv[0].equalsIgnoreCase("prc")) java.util.Locale.setDefault(java.util.Locale.PRC); if (argv[0].equalsIgnoreCase("taiwan")) java.util.Locale.setDefault(java.util.Locale.TAIWAN); if (argv[0].equalsIgnoreCase("uk")) java.util.Locale.setDefault(java.util.Locale.UK); if (argv[0].equalsIgnoreCase("us")) java.util.Locale.setDefault(java.util.Locale.US); }/*from w ww .j ava 2 s .c om*/ String localeString = java.util.Locale.getDefault().getDisplayName(); JFrame f = new JFrame("SimpleFTF " + localeString); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setContentPane(new SimpleFTF()); f.pack(); f.setVisible(true); }
From source file:DropModeINSERT.java
public static void main(String[] args) { JPanel north = new JPanel(); north.add(new JLabel("Drag from here:")); JTextField field = new JTextField(10); field.setDragEnabled(true);//from ww w . j av a 2 s . co m north.add(field); final DefaultListModel listModel = new DefaultListModel(); listModel.addElement("first"); listModel.addElement("second"); final JList list = new JList(listModel); list.setDragEnabled(true); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() == -1) { return false; } else { return true; } } public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } Transferable transferable = support.getTransferable(); String data; try { data = (String) transferable.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { listModel.add(index, data); } else { listModel.set(index, data); } // Scroll to display the element that was dropped Rectangle r = list.getCellBounds(index, index); list.scrollRectToVisible(r); return true; } }); JScrollPane center = new JScrollPane(); center.setViewportView(list); list.setDropMode(DropMode.INSERT); JPanel cp = new JPanel(); cp.setLayout(new BorderLayout()); cp.add(north, BorderLayout.NORTH); cp.add(center, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }