List of usage examples for java.awt Dimension Dimension
public Dimension(int width, int height)
From source file:CheckBoxMenuItemExample.java
public static void main(String s[]) { CheckBoxMenuItemExample example = new CheckBoxMenuItemExample(); example.pane = new JTextPane(); example.pane.setPreferredSize(new Dimension(250, 250)); example.pane.setBorder(new BevelBorder(BevelBorder.LOWERED)); JFrame frame = new JFrame("Menu Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(example.menuBar);//w w w . j a va 2 s . c o m frame.getContentPane().add(example.pane, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:Starry.java
public static void main(String[] args) { Image starry = new ImageIcon("yourFile.gif").getImage(); StarPanel starPanel = new StarPanel(starry); JFrame f = new JFrame("Starry"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/* w ww. j a v a 2 s .c o m*/ } }); f.getContentPane().add(starPanel, BorderLayout.CENTER); f.setSize(new Dimension(550, 200)); f.setVisible(true); }
From source file:RadioButtonMenuItemExample.java
public static void main(String s[]) { RadioButtonMenuItemExample example = new RadioButtonMenuItemExample(); example.pane = new JTextPane(); example.pane.setPreferredSize(new Dimension(250, 250)); example.pane.setBorder(new BevelBorder(BevelBorder.LOWERED)); JFrame frame = new JFrame("Menu Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(example.menuBar);/*from w w w. j ava2s .co m*/ frame.getContentPane().add(example.pane, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:OverlaySample.java
public static void main(String args[]) { ActionListener generalActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JComponent comp = (JComponent) actionEvent.getSource(); System.out.println(actionEvent.getActionCommand() + ": " + comp.getBounds()); }/*from www. j ava 2 s . c om*/ }; ActionListener sizingActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { setupButtons(actionEvent.getActionCommand()); } }; JFrame frame = new JFrame("Overlay Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); LayoutManager overlay = new OverlayLayout(panel); panel.setLayout(overlay); Object settings[][] = { { "Small", new Dimension(25, 25), Color.white }, { "Medium", new Dimension(50, 50), Color.gray }, { "Large", new Dimension(100, 100), Color.black } }; JButton buttons[] = { smallButton, mediumButton, largeButton }; for (int i = 0, n = settings.length; i < n; i++) { JButton button = buttons[i]; button.addActionListener(generalActionListener); button.setActionCommand((String) settings[i][0]); button.setMaximumSize((Dimension) settings[i][1]); button.setBackground((Color) settings[i][2]); panel.add(button); } setupButtons(SET_CENTRAL); JPanel actionPanel = new JPanel(); actionPanel.setBorder(BorderFactory.createTitledBorder("Change Alignment")); String actionSettings[] = { SET_MINIMUM, SET_MAXIMUM, SET_CENTRAL, SET_MIXED }; for (int i = 0, n = actionSettings.length; i < n; i++) { JButton button = new JButton(actionSettings[i]); button.addActionListener(sizingActionListener); actionPanel.add(button); } Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(actionPanel, BorderLayout.SOUTH); frame.setSize(400, 300); frame.setVisible(true); }
From source file:DocumentModel.java
public static void main(String[] args) { final StyledDocument doc; final JTextPane textpane; JFrame f = new JFrame(); f.setTitle("Document Model"); JToolBar toolbar = new JToolBar(); JButton boldb = new JButton("bold"); JButton italb = new JButton("italic"); JButton strib = new JButton("strike"); JButton undeb = new JButton("underline"); toolbar.add(boldb);/*www .ja va2s.co m*/ toolbar.add(italb); toolbar.add(strib); toolbar.add(undeb); f.add(toolbar, BorderLayout.NORTH); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); JScrollPane pane = new JScrollPane(); textpane = new JTextPane(); textpane.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); doc = textpane.getStyledDocument(); Style style = textpane.addStyle("Bold", null); StyleConstants.setBold(style, true); style = textpane.addStyle("Italic", null); StyleConstants.setItalic(style, true); style = textpane.addStyle("Underline", null); StyleConstants.setUnderline(style, true); style = textpane.addStyle("Strike", null); StyleConstants.setStrikeThrough(style, true); boldb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Bold"), false); } }); italb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Italic"), false); } }); strib.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Strike"), false); } }); undeb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Underline"), false); } }); pane.getViewport().add(textpane); panel.add(pane); f.add(panel); f.setSize(new Dimension(380, 320)); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:it.iit.genomics.cru.igb.bundles.mi.view.TestJung.java
public static void main(String[] args) { Graph<MoleculeEntry, EdgeInteraction> graph = new SparseMultigraph<>(); MoleculeEntry v1 = new MoleculeEntry("A"); v1.addGeneName("A"); v1.setTaxid("9606"); MoleculeEntry v2 = new MoleculeEntry("B"); v2.addGeneName("b"); v2.setTaxid("9606"); MoleculeEntry v3 = new MoleculeEntry("DNA"); v3.addGeneName("DNA"); v3.setTaxid(MoleculeEntry.TAXID_DNA); EdgeInteraction edge = new EdgeInteraction(true, true, true, "e1"); graph.addEdge(edge, v1, v2, EdgeType.UNDIRECTED); EdgeInteraction edge2 = new EdgeInteraction(false, false, true, "e2"); graph.addEdge(edge2, v1, v3, EdgeType.UNDIRECTED); EdgeInteraction edge3 = new EdgeInteraction(false, false, false, "e3"); graph.addEdge(edge3, v2, v3, EdgeType.UNDIRECTED); // The Layout<V, E> is parameterized by the vertex and edge types Layout<MoleculeEntry, EdgeInteraction> layout = new ISOMLayout(graph); layout.setSize(new Dimension(500, 600)); // sets the initial size of the space // The BasicVisualizationServer<V,E> is parameterized by the edge types VisualizationViewer<MoleculeEntry, EdgeInteraction> vv = new VisualizationViewer<>(layout); vv.setPreferredSize(new Dimension(550, 650)); //Sets the viewing area size vv.setBackground(Color.WHITE); Transformer<MoleculeEntry, Paint> vertexPaint = new Transformer<MoleculeEntry, Paint>() { @Override//from www . j ava 2 s .c o m public Paint transform(MoleculeEntry molecule) { switch (molecule.getTaxid()) { case MoleculeEntry.TAXID_DNA: ; case MoleculeEntry.TAXID_RNA: return Color.GREEN; case MoleculeEntry.TAXID_LIGAND: return Color.MAGENTA; default: return Color.GREEN; } } }; Transformer<EdgeInteraction, Paint> edgePaint = new Transformer<EdgeInteraction, Paint>() { @Override public Paint transform(EdgeInteraction interaction) { return interaction.hasStructure ? Color.BLACK : Color.GRAY; } }; final Stroke edgeStroke01 = new BasicStroke(); final float nodeSize = 20; final Stroke edgeStrokeBothContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) }, nodeSize, true, true); final Stroke edgeStrokeStartContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) }, nodeSize, true, false); final Stroke edgeStrokeEndContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) }, nodeSize, false, true); final Stroke edgeStrokeBothContact = new CompoundStroke(edgeStroke01, edgeStrokeBothContacts, CompoundStroke.ADD); final Stroke edgeStrokeStartContact = new CompoundStroke(edgeStroke01, edgeStrokeStartContacts, CompoundStroke.ADD); final Stroke edgeStrokeEndContact = new CompoundStroke(edgeStroke01, edgeStrokeEndContacts, CompoundStroke.ADD); Transformer<EdgeInteraction, Stroke> edgeStrokeTransformer = new Transformer<EdgeInteraction, Stroke>() { @Override public Stroke transform(EdgeInteraction s) { if (s.hasContactsA && s.hasContactsB) { return edgeStrokeBothContact; } if (s.hasContactsA) { return edgeStrokeStartContact; } if (s.hasContactsB) { return edgeStrokeEndContact; } return edgeStroke01; } }; Transformer<MoleculeEntry, String> moleculeLabeller = new Transformer<MoleculeEntry, String>() { @Override public String transform(MoleculeEntry s) { return s.getGeneName(); } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); vv.getRenderContext().setEdgeDrawPaintTransformer(edgePaint); vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer); vv.getRenderContext().setVertexLabelTransformer(moleculeLabeller); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(graphMouse); JFrame frame = new JFrame("Network " + "A"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(vv); frame.pack(); frame.setVisible(true); }
From source file:LineBreakSample.java
public static void main(String[] args) { JFrame f = new JFrame(""); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/* ww w . j av a2 s . c o m*/ } }); LineBreakSample controller = new LineBreakSample(); f.getContentPane().add(controller, "Center"); f.setSize(new Dimension(400, 250)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel gui = new JPanel(new BorderLayout(5, 5)); JPanel plafComponents = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 3)); plafComponents.setBorder(new TitledBorder("FlowLayout(FlowLayout.RIGHT, 3,3)")); UIManager.LookAndFeelInfo[] plafInfos = UIManager.getInstalledLookAndFeels(); String[] plafNames = new String[plafInfos.length]; for (int ii = 0; ii < plafInfos.length; ii++) { plafNames[ii] = plafInfos[ii].getName(); }/*from www. j ava 2 s . co m*/ JComboBox plafChooser = new JComboBox(plafNames); plafComponents.add(plafChooser); JCheckBox pack = new JCheckBox("Pack on PLAF change", true); plafComponents.add(pack); plafChooser.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int index = plafChooser.getSelectedIndex(); try { UIManager.setLookAndFeel(plafInfos[index].getClassName()); SwingUtilities.updateComponentTreeUI(frame); if (pack.isSelected()) { frame.pack(); frame.setMinimumSize(frame.getSize()); } } catch (Exception e) { e.printStackTrace(); } } }); gui.add(plafComponents, BorderLayout.NORTH); JPanel dynamicLabels = new JPanel(new BorderLayout(4, 4)); dynamicLabels.setBorder(new TitledBorder("BorderLayout(4,4)")); gui.add(dynamicLabels, BorderLayout.WEST); final JPanel labels = new JPanel(new GridLayout(0, 2, 3, 3)); labels.setBorder(new TitledBorder("GridLayout(0,2,3,3)")); JButton addNew = new JButton("Add Another Label"); dynamicLabels.add(addNew, BorderLayout.NORTH); addNew.addActionListener(new ActionListener() { private int labelCount = 0; public void actionPerformed(ActionEvent ae) { labels.add(new JLabel("Label " + ++labelCount)); frame.validate(); } }); dynamicLabels.add(new JScrollPane(labels), BorderLayout.CENTER); String[] header = { "Name", "Value" }; String[] a = new String[0]; String[] names = System.getProperties().stringPropertyNames().toArray(a); String[][] data = new String[names.length][2]; for (int ii = 0; ii < names.length; ii++) { data[ii][0] = names[ii]; data[ii][1] = System.getProperty(names[ii]); } DefaultTableModel model = new DefaultTableModel(data, header); JTable table = new JTable(model); JScrollPane tableScroll = new JScrollPane(table); Dimension tablePreferred = tableScroll.getPreferredSize(); tableScroll.setPreferredSize(new Dimension(tablePreferred.width, tablePreferred.height / 3)); JPanel imagePanel = new JPanel(new GridBagLayout()); JLabel imageLabel = new JLabel("test"); imagePanel.add(imageLabel, null); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableScroll, new JScrollPane(imagePanel)); gui.add(splitPane, BorderLayout.CENTER); frame.setContentPane(gui); frame.pack(); frame.setVisible(true); }
From source file:HitTestSample.java
public static void main(String[] args) { JFrame f = new JFrame("HitTestSample"); HitTestSample demo = new HitTestSample(); f.getContentPane().add(demo, "Center"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);// w w w . ja v a 2 s.com } }); f.setSize(new Dimension(400, 250)); f.setVisible(true); }
From source file:com.opendoorlogistics.studio.components.map.plugins.snapshot.ExportImagePanel.java
public static void main(String[] args) { ShowPanel.showPanel(new ExportImagePanel(new Dimension(200, 400))); }