List of usage examples for javax.swing JFrame JFrame
public JFrame(String title) throws HeadlessException
Frame
with the specified title. From source file:MnemonicSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Mnemonics"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(1, 0)); JButton button1 = new JButton("Warning"); button1.setMnemonic(KeyEvent.VK_W); content.add(button1);/*from www .j a va 2 s .c o m*/ JButton button2 = new JButton("Warning"); button2.setMnemonic(KeyEvent.VK_H); content.add(button2); frame.setSize(300, 200); frame.setVisible(true); }
From source file:PopupSample.java
public static void main(final String args[]) { JFrame frame = new JFrame("PopupSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create popup menu, attach popup menu listener JPopupMenu popupMenu = new JPopupMenu("Title"); // Cut//from w w w. j ava 2 s. com JMenuItem cutMenuItem = new JMenuItem("Cut"); popupMenu.add(cutMenuItem); // Copy JMenuItem copyMenuItem = new JMenuItem("Copy"); popupMenu.add(copyMenuItem); // Paste JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); // Separator popupMenu.addSeparator(); // Find JMenuItem findMenuItem = new JMenuItem("Find"); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }
From source file:ApplicationModalDialogWithExcludeDemo.java
public static void main(String[] args) { final JFrame parent1 = new JFrame("Parent Frame 1"); parent1.setLayout(new FlowLayout()); parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); parent1.setBounds(100, 100, 200, 150); parent1.setVisible(true);//from www.j av a2 s . com JFrame parent2 = new JFrame("Parent Frame 2"); parent2.setBounds(500, 100, 300, 150); parent2.setVisible(true); JFrame parent3 = new JFrame("Parent Frame 3 - Excluded"); parent3.setBounds(300, 400, 300, 150); parent3.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); parent3.setVisible(true); JDialog dialog = new JDialog(parent1, "Application-Modal Dialog", Dialog.ModalityType.APPLICATION_MODAL); dialog.setBounds(300, 200, 300, 150); dialog.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("EditorPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try {/*from www. j a va2 s . c om*/ JEditorPane editorPane = new JEditorPane("http://www.java2s.com"); editorPane.setEditable(false); boolean b = editorPane.getScrollableTracksViewportWidth(); JScrollPane scrollPane = new JScrollPane(editorPane); frame.add(scrollPane); } catch (IOException e) { System.err.println("Unable to load: " + e); } frame.setSize(640, 480); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Justified Titled Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = BorderFactory.createRaisedBevelBorder(); JButton raisedButton = new JButton("Raised"); raisedButton.setBorder(raisedBorder); Container contentPane = frame.getContentPane(); contentPane.add(raisedButton);//from ww w .j a v a 2s. c o m frame.setSize(300, 200); frame.setVisible(true); }
From source file:EtchedBorderSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, Color.RED, Color.PINK); JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(etchedBorder);/*from w w w . ja va 2 s.co m*/ aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("EditorPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try {//from w w w . j a v a 2 s .com JEditorPane editorPane = new JEditorPane("http://www.java2s.com"); editorPane.setEditable(false); boolean b = editorPane.getScrollableTracksViewportHeight(); JScrollPane scrollPane = new JScrollPane(editorPane); frame.add(scrollPane); } catch (IOException e) { System.err.println("Unable to load: " + e); } frame.setSize(640, 480); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("EditorPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try {/*from ww w .jav a 2 s .co m*/ JEditorPane editorPane = new JEditorPane("http://www.java2s.com"); editorPane.setEditable(false); Dimension dimension = editorPane.getPreferredSize(); JScrollPane scrollPane = new JScrollPane(editorPane); frame.add(scrollPane); } catch (IOException e) { System.err.println("Unable to load: " + e); } frame.setSize(640, 480); frame.setVisible(true); }
From source file:AncestorSampler.java
public static void main(String args[]) { JFrame frame = new JFrame("Ancestor Sampler"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); AncestorListener ancestorListener = new AncestorListener() { public void ancestorAdded(AncestorEvent ancestorEvent) { System.out.println("Added"); }/*from w ww.jav a 2 s . c o m*/ public void ancestorMoved(AncestorEvent ancestorEvent) { System.out.println("Moved"); } public void ancestorRemoved(AncestorEvent ancestorEvent) { System.out.println("Removed"); } }; JButton bn = new JButton(); bn.addAncestorListener(ancestorListener); frame.add(bn); //frame.remove(bn); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Positioned Titled Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TitledBorder aboveTopBorder = BorderFactory.createTitledBorder("AboveTop"); aboveTopBorder.setTitlePosition(TitledBorder.ABOVE_TOP); JButton aboveTopButton = new JButton(); aboveTopButton.setBorder(aboveTopBorder); Container contentPane = frame.getContentPane(); contentPane.add(aboveTopButton);/* www . java2 s.co m*/ frame.setSize(300, 200); frame.setVisible(true); }