List of usage examples for javax.swing JFrame getContentPane
public Container getContentPane()
contentPane
object for this frame. From source file:CaretSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Caret Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); content.add(scrollPane, BorderLayout.CENTER); final JTextField dot = new JTextField(); dot.setEditable(false);//ww w . j av a 2 s . c o m JPanel dotPanel = new JPanel(new BorderLayout()); dotPanel.add(new JLabel("Dot: "), BorderLayout.WEST); dotPanel.add(dot, BorderLayout.CENTER); content.add(dotPanel, BorderLayout.NORTH); final JTextField mark = new JTextField(); mark.setEditable(false); JPanel markPanel = new JPanel(new BorderLayout()); markPanel.add(new JLabel("Mark: "), BorderLayout.WEST); markPanel.add(mark, BorderLayout.CENTER); content.add(markPanel, BorderLayout.SOUTH); CaretListener listener = new CaretListener() { public void caretUpdate(CaretEvent caretEvent) { dot.setText("" + caretEvent.getDot()); mark.setText("" + caretEvent.getMark()); } }; textArea.addCaretListener(listener); frame.setSize(250, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.add(new Justify()); f.pack();// w ww .j av a 2 s .c o m f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { BoundedRangeModel model = new DefaultBoundedRangeModel(); BlockedColorLayerUI layerUI = new BlockedColorLayerUI(); JPanel p = new JPanel(new GridLayout(2, 1, 12, 12)); p.add(new JLayer<JProgressBar>(new JProgressBar(model), layerUI)); JPanel box = new JPanel(); box.add(new JButton(new AbstractAction("+10") { private int i = 0; @Override/*from ww w .j a v a2s .c om*/ public void actionPerformed(ActionEvent e) { model.setValue(i = (i >= 100) ? 0 : i + 10); } })); p.repaint(); JPanel panel = new JPanel(new BorderLayout()); panel.add(p, BorderLayout.NORTH); panel.add(box, BorderLayout.SOUTH); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(panel); f.setSize(320, 240); f.setVisible(true); }
From source file:DefaultSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Default Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); JTextField textField = new JTextField(); content.add(textField, BorderLayout.NORTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand() + " selected"); }/*from w w w. jav a2s . com*/ }; JPanel panel = new JPanel(); JButton defaultButton = new JButton("Default Button"); defaultButton.addActionListener(actionListener); panel.add(defaultButton); JButton otherButton = new JButton("Other Button"); otherButton.addActionListener(actionListener); panel.add(otherButton); content.add(panel, BorderLayout.SOUTH); Keymap keymap = textField.getKeymap(); KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false); keymap.removeKeyStrokeBinding(keystroke); frame.getRootPane().setDefaultButton(defaultButton); frame.setSize(250, 150); frame.setVisible(true); }
From source file:TextLayoutWithMouseClickDrag.java
public static void main(String arg[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add("Center", new DisplayPanel()); frame.pack();//from w w w . java 2 s .c om frame.setSize(new Dimension(400, 300)); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JFrame aWindow = new JFrame(); aWindow.setBounds(200, 200, 200, 200); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = aWindow.getContentPane(); content.add(new MouseMotionAnonymous()); aWindow.setVisible(true);/*from w ww. j a va2 s.c o m*/ }
From source file:ThreadLister.java
/** * The main() method create a simple graphical user interface to display the * threads in. This allows us to see the "event dispatch thread" used by AWT * and Swing.//from w w w . j a v a2s . c om */ public static void main(String[] args) { // Create a simple Swing GUI JFrame frame = new JFrame("ThreadLister Demo"); JTextArea textarea = new JTextArea(); frame.getContentPane().add(new JScrollPane(textarea), BorderLayout.CENTER); frame.setSize(500, 400); frame.setVisible(true); // Get the threadlisting as a string using a StringWriter stream StringWriter sout = new StringWriter(); // To capture the listing PrintWriter out = new PrintWriter(sout); ThreadLister.listAllThreads(out); // List threads to stream out.close(); String threadListing = sout.toString(); // Get listing as a string // Finally, display the thread listing in the GUI textarea.setText(threadListing); }
From source file:LabelJarSample.java
public static void main(String args[]) { String title = "JLabel Sample"; JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(2, 2)); JLabel label1 = new JLabel("Text Label"); content.add(label1);//from w w w. j ava 2 s . c om Image warnImage = ImageLoader.getImage(LabelJarSample.class, "Warn.gif"); Icon warnIcon = new ImageIcon(warnImage); JLabel label2 = new JLabel(warnIcon); content.add(label2); JLabel label3 = new JLabel("Warning", warnIcon, JLabel.CENTER); content.add(label3); String htmlLabel = "<html><sup>HTML</sup> <sub><em>Label</em></sub><br>" + "<font color=\"#FF0080\"><u>Multi-line</u></font>"; JLabel label4 = new JLabel(htmlLabel); content.add(label4); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); ImageIcon ii = new ImageIcon("largeJava2sLogo.gif"); JScrollPane jsp = new JScrollPane(new ScrollableLabel(ii)); f.getContentPane().add(jsp); f.setSize(300, 250);/*from w w w .j a v a 2s .c o m*/ f.setVisible(true); }
From source file:LoadSave.java
public static void main(String args[]) { final String filename = "text.out"; JFrame frame = new JFrame("Loading/Saving Example"); Container content = frame.getContentPane(); final JTextField textField = new JTextField(); content.add(textField, BorderLayout.NORTH); JPanel panel = new JPanel(); Action loadAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { try { doLoadCommand(textField, filename); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace();//from w ww.j a v a 2s . c om } } }; loadAction.putValue(Action.NAME, "Load"); JButton loadButton = new JButton(loadAction); panel.add(loadButton); Action saveAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { try { doSaveCommand(textField, filename); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }; saveAction.putValue(Action.NAME, "Save"); JButton saveButton = new JButton(saveAction); panel.add(saveButton); Action clearAction = new AbstractAction() { { putValue(Action.NAME, "Clear"); } public void actionPerformed(ActionEvent e) { textField.setText(""); } }; JButton clearButton = new JButton(clearAction); panel.add(clearButton); content.add(panel, BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }