List of usage examples for javax.swing JFrame setSize
public void setSize(int width, int height)
The width and height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JTree Demo"); f.setSize(260, 240); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root"); DefaultMutableTreeNode aNode = new DefaultMutableTreeNode("A"); root.add(aNode);// w w w . j av a 2 s. c o m DefaultMutableTreeNode bNode = new DefaultMutableTreeNode("B"); aNode.add(bNode); DefaultMutableTreeNode cNode = new DefaultMutableTreeNode("C"); aNode.add(cNode); cNode.add(new DefaultMutableTreeNode("D")); cNode.add(new DefaultMutableTreeNode("E")); DefaultMutableTreeNode fNode = new DefaultMutableTreeNode("F"); root.add(fNode); DefaultMutableTreeNode gNode = new DefaultMutableTreeNode("G"); fNode.add(gNode); fNode.add(new DefaultMutableTreeNode("H")); gNode.add(new DefaultMutableTreeNode("I")); JTree jtree = new JTree(root); jtree.setEditable(true); TreeSelectionModel tsm = jtree.getSelectionModel(); tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jtree.addTreeExpansionListener(new TreeExpansionListener() { public void treeExpanded(TreeExpansionEvent tee) { TreePath tp = tee.getPath(); System.out.println("Expansion: " + tp.getLastPathComponent()); } public void treeCollapsed(TreeExpansionEvent tee) { TreePath tp = tee.getPath(); System.out.println("Collapse: " + tp.getLastPathComponent()); } }); jtree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent tse) { TreePath tp = tse.getPath(); System.out.println("Selection event: " + tp.getLastPathComponent()); } }); jtree.getModel().addTreeModelListener(new TreeModelListener() { public void treeNodesChanged(TreeModelEvent tme) { TreePath tp = tme.getTreePath(); Object[] children = tme.getChildren(); DefaultMutableTreeNode changedNode; if (children != null) changedNode = (DefaultMutableTreeNode) children[0]; else changedNode = (DefaultMutableTreeNode) tp.getLastPathComponent(); System.out.println("Model change path: " + tp + "New data: " + changedNode.getUserObject()); } public void treeNodesInserted(TreeModelEvent tme) { } public void treeNodesRemoved(TreeModelEvent tme) { } public void treeStructureChanged(TreeModelEvent tme) { } }); f.add(new JScrollPane(jtree)); f.setVisible(true); }
From source file:Main.java
public static void main(final String[] args) throws IOException { final URL url1 = new URL("http://www.java2s.com/style/download.png"); final URL url2 = new URL("http://www.java2s.com/style/download.png"); final URL url3 = new URL("http://www.java2s.com/style/download.png"); final PictureDesktop desktop = new PictureDesktop(); desktop.addPicture(ImageIO.read(url1)); desktop.addPicture(ImageIO.read(url2)); desktop.addPicture(ImageIO.read(url3)); final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(BorderLayout.CENTER, desktop); frame.setSize(720, 480); frame.setVisible(true);/*from w ww. j av a 2s . c o m*/ }
From source file:MainClass.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.getContentPane().add(new MainClass()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true);/*from w w w .j a v a 2 s .c o m*/ }
From source file:TransformersRotationTranslation.java
public static void main(String[] a) { JFrame f = new JFrame(); f.getContentPane().add(new TransformersRotationTranslation()); f.setSize(350, 450); f.show();/*from w w w . j a v a 2 s.c om*/ }
From source file:MainClass.java
public static void main(String[] args) { // create a hierarchy of nodes MutableTreeNode root = new DefaultMutableTreeNode("A"); MutableTreeNode bNode = new DefaultMutableTreeNode("B"); MutableTreeNode cNode = new DefaultMutableTreeNode("C"); root.insert(bNode, 0);/*from ww w . j av a 2s .c om*/ root.insert(cNode, 1); bNode.insert(new DefaultMutableTreeNode("1"), 0); bNode.insert(new DefaultMutableTreeNode("2"), 1); cNode.insert(new DefaultMutableTreeNode("1"), 0); cNode.insert(new DefaultMutableTreeNode("2"), 1); final DefaultTreeModel model = new DefaultTreeModel(root); final JTree tree = new JTree(model); final JTextField nameField = new JTextField("Z"); final JButton button = new JButton("Add"); button.setEnabled(false); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { TreePath tp = tree.getSelectionPath(); MutableTreeNode insertNode = (MutableTreeNode) tp.getLastPathComponent(); int insertIndex = 0; if (insertNode.getParent() != null) { MutableTreeNode parent = (MutableTreeNode) insertNode.getParent(); insertIndex = parent.getIndex(insertNode) + 1; insertNode = parent; } MutableTreeNode node = new DefaultMutableTreeNode(nameField.getText()); model.insertNodeInto(node, insertNode, insertIndex); } }); JPanel addPanel = new JPanel(new GridLayout(2, 1)); addPanel.add(nameField); addPanel.add(button); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { TreePath tp = e.getNewLeadSelectionPath(); button.setEnabled(tp != null); } }); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.getContentPane().add(new JScrollPane(tree)); frame.getContentPane().add(addPanel, BorderLayout.SOUTH); frame.setVisible(true); }
From source file:MouseClickListener.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("MouseListener Test 1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addMouseListener(new MouseClickListener()); frame.setSize(200, 200); frame.setVisible(true);/*from w ww . j av a2 s . com*/ }
From source file:MainClass.java
public static void main(String s[]) { JFrame frame = new JFrame("Scroll Bar Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new MainClass()); frame.setSize(200, 200); frame.setVisible(true);//from w w w. j a v a 2 s . c om }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("<html>bold <br> plain</html>"); frame.add(label);/* w ww. j ava2 s . c o m*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new Main().makeUI()); frame.setSize(320, 240); frame.setVisible(true);/*from ww w . ja v a 2 s. c om*/ }
From source file:FileTableHTML.java
public static void main(String[] args) throws IOException { // Get the name of the directory to display String dirname = (args.length > 0) ? args[0] : System.getProperty("user.home"); // Create something to display it in. final JEditorPane editor = new JEditorPane(); editor.setEditable(false); // we're browsing not editing editor.setContentType("text/html"); // must specify HTML text editor.setText(makeHTMLTable(dirname)); // specify the text to display // Set up the JEditorPane to handle clicks on hyperlinks editor.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { // Handle clicks; ignore mouseovers and other link-related events if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { // Get the HREF of the link and display it. editor.setText(makeHTMLTable(e.getDescription())); }//from w w w . ja va 2s . c o m } }); // Put the JEditorPane in a scrolling window and display it. JFrame frame = new JFrame("FileTableHTML"); frame.getContentPane().add(new JScrollPane(editor)); frame.setSize(650, 500); frame.setVisible(true); }