List of usage examples for java.awt Container setPreferredSize
public void setPreferredSize(Dimension preferredSize)
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame("Fixed size content"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Container c = f.getContentPane(); c.setBackground(Color.YELLOW); Dimension d = new Dimension(400, 40); c.setPreferredSize(d); f.pack();//from w ww. j a va2 s .c o m f.setResizable(false); f.setVisible(true); }
From source file:Main.java
/** * Create a component buffer of width w and height h * //from w ww . ja va 2s.c o m * @param width * @param height * @return */ public static Component createBufferPanel(int width, int height) { Container buffer = new Container(); buffer.setMinimumSize(new Dimension(width, height)); buffer.setPreferredSize(new Dimension(width, height)); buffer.setMaximumSize(new Dimension(width, height)); return buffer; }
From source file:edu.oregonstate.eecs.mcplan.domains.planetwars.PwVisualization.java
public PwVisualization(final PwGame game, final Dimension dim, final int width, final int height, final int sleep) { super("Planet Wars!"); this.sleep = sleep; final Container cp = getContentPane(); cp.setPreferredSize(dim); cp.setLayout(null);/*from w ww . j a v a 2 s . c o m*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setResizable(false); setVisible(true); canvas = new PwVisualizationCanvas(this, game, width, height); canvas.setBounds(0, 0, dim.width, dim.height); }
From source file:net.openbyte.gui.CreateProjectFrame.java
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner Evaluation license - Gary Lee button1 = new JButton(); textField1 = new JTextField(); label1 = new JLabel(); comboBox1 = new JComboBox<>(); label2 = new JLabel(); comboBox2 = new JComboBox<>(); label3 = new JLabel(); button2 = new JButton(); //======== this ======== setTitle("Project Creation"); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); setResizable(false);//w w w.ja va2 s .c om Container contentPane = getContentPane(); contentPane.setLayout(null); //---- button1 ---- button1.setText("Create project"); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button1ActionPerformed(e); } }); contentPane.add(button1); button1.setBounds(new Rectangle(new Point(340, 170), button1.getPreferredSize())); contentPane.add(textField1); textField1.setBounds(10, 25, 245, textField1.getPreferredSize().height); //---- label1 ---- label1.setText("Project Name"); contentPane.add(label1); label1.setBounds(new Rectangle(new Point(10, 5), label1.getPreferredSize())); //---- comboBox1 ---- comboBox1.setModel(new DefaultComboBoxModel<>(new String[] { "Minecraft Forge", "MCP", "Bukkit" })); comboBox1.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { comboBox1ItemStateChanged(e); } }); contentPane.add(comboBox1); comboBox1.setBounds(10, 70, 245, comboBox1.getPreferredSize().height); //---- label2 ---- label2.setText("Modification API"); contentPane.add(label2); label2.setBounds(new Rectangle(new Point(10, 50), label2.getPreferredSize())); //---- comboBox2 ---- comboBox2.setModel(new DefaultComboBoxModel<>(new String[] { "1.8.9", "1.7.10" })); contentPane.add(comboBox2); comboBox2.setBounds(10, 120, 245, comboBox2.getPreferredSize().height); //---- label3 ---- label3.setText("Minecraft Version"); contentPane.add(label3); label3.setBounds(new Rectangle(new Point(10, 100), label3.getPreferredSize())); //---- button2 ---- button2.setText("Cancel"); button2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button2ActionPerformed(e); } }); contentPane.add(button2); button2.setBounds(new Rectangle(new Point(10, 170), button2.getPreferredSize())); { // compute preferred size Dimension preferredSize = new Dimension(); for (int i = 0; i < contentPane.getComponentCount(); i++) { Rectangle bounds = contentPane.getComponent(i).getBounds(); preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); } Insets insets = contentPane.getInsets(); preferredSize.width += insets.right; preferredSize.height += insets.bottom; contentPane.setMinimumSize(preferredSize); contentPane.setPreferredSize(preferredSize); } setSize(480, 240); setLocationRelativeTo(getOwner()); // JFormDesigner - End of component initialization //GEN-END:initComponents }
From source file:net.openbyte.gui.WelcomeFrame.java
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner Evaluation license - Gary Lee scrollPane1 = new JScrollPane(); list1 = new JList(); button1 = new JButton(); label2 = new JLabel(); button2 = new JButton(); button3 = new JButton(); button4 = new JButton(); button5 = new JButton(); scrollPane2 = new JScrollPane(); xImagePanel1 = new JXImagePanel(); button6 = new JButton(); button7 = new JButton(); button8 = new JButton(); //======== this ======== setTitle("Welcome to OpenByte"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setResizable(false);/* w w w .j a va2 s . c om*/ Container contentPane = getContentPane(); contentPane.setLayout(null); //======== scrollPane1 ======== { scrollPane1.setBorder(new TitledBorder(LineBorder.createGrayLineBorder(), "Recent Projects")); //---- list1 ---- list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list1.setBackground(new Color(240, 240, 240)); list1.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { list1ValueChanged(e); } }); scrollPane1.setViewportView(list1); } contentPane.add(scrollPane1); scrollPane1.setBounds(15, 10, 165, 340); //---- button1 ---- button1.setText("Open Project"); button1.setEnabled(false); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button1ActionPerformed(e); } }); contentPane.add(button1); button1.setBounds(105, 355, 110, button1.getPreferredSize().height); //---- label2 ---- label2.setText("Media"); contentPane.add(label2); label2.setBounds(new Rectangle(new Point(605, 210), label2.getPreferredSize())); //---- button2 ---- button2.setText("Minecraft Forums"); button2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button2ActionPerformed(e); } }); contentPane.add(button2); button2.setBounds(500, 230, 151, button2.getPreferredSize().height); //---- button3 ---- button3.setText("GitHub"); button3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button3ActionPerformed(e); } }); contentPane.add(button3); button3.setBounds(500, 260, 150, button3.getPreferredSize().height); //---- button4 ---- button4.setText("+"); button4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button4ActionPerformed(e); } }); contentPane.add(button4); button4.setBounds(15, 355, 45, button4.getPreferredSize().height); //---- button5 ---- button5.setText("-"); button5.setEnabled(false); button5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button5ActionPerformed(e); } }); contentPane.add(button5); button5.setBounds(60, 355, 40, button5.getPreferredSize().height); //======== scrollPane2 ======== { scrollPane2.setBorder(null); scrollPane2.setViewportView(xImagePanel1); } contentPane.add(scrollPane2); scrollPane2.setBounds(210, 25, 445, 160); //---- button6 ---- button6.setText("Preferences"); button6.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button6ActionPerformed(e); } }); contentPane.add(button6); button6.setBounds(500, 290, 150, 30); //---- button7 ---- button7.setText("About"); button7.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button7ActionPerformed(e); } }); contentPane.add(button7); button7.setBounds(500, 320, 150, 30); //---- button8 ---- button8.setText("Plugins"); button8.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button8ActionPerformed(e); } }); contentPane.add(button8); button8.setBounds(500, 350, 150, 30); { // compute preferred size Dimension preferredSize = new Dimension(); for (int i = 0; i < contentPane.getComponentCount(); i++) { Rectangle bounds = contentPane.getComponent(i).getBounds(); preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); } Insets insets = contentPane.getInsets(); preferredSize.width += insets.right; preferredSize.height += insets.bottom; contentPane.setMinimumSize(preferredSize); contentPane.setPreferredSize(preferredSize); } setSize(675, 425); setLocationRelativeTo(getOwner()); // JFormDesigner - End of component initialization //GEN-END:initComponents }
From source file:model.DrawTopologyDiagram.java
@Override public void init() { //create a graph Graph<VertexTopology, Number> ig = Graphs.<VertexTopology, Number>synchronizedDirectedGraph( new DirectedSparseMultigraph<VertexTopology, Number>()); ObservableGraph<VertexTopology, Number> og = new ObservableGraph<VertexTopology, Number>(ig); og.addGraphEventListener(new GraphEventListener<VertexTopology, Number>() { public void handleGraphEvent(GraphEvent<VertexTopology, Number> evt) { System.err.println("got " + evt); }/*from ww w . j av a 2s. co m*/ }); this.g = og; //layouts //create a graphdraw // layout = new FRLayout2<String,Number>(g); // layout = new SpringLayout<String,Number>(g); // ((FRLayout)layout).setMaxIterations(200); layout = new KKLayout<VertexTopology, Number>(g); vv = new VisualizationViewer<VertexTopology, Number>(layout, new Dimension(600, 600)); createGraph(); Container content = getContentPane(); JPanel totalCasesPanel = new JPanel(); final JPanel scaleGrids = new JPanel(new GridLayout(0, 2)); scaleGrids.add(new JLabel(" Test Cases ")); scaleGrids.add(new JLabel(" ")); totalCasesPanel.add(scaleGrids); JPanel filteredCasesPanel = new JPanel(); final JPanel filteredGrids = new JPanel(new GridLayout(0, 2)); filteredGrids.add(new JLabel(" Filtered Cases ")); filteredGrids.add(new JLabel(" ")); filteredCasesPanel.add(filteredGrids); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); content.setLayout(new BorderLayout()); content.setBackground(java.awt.Color.lightGray); content.setFont(new Font("Serif", Font.PLAIN, 12)); vv.getModel().getRelaxer().setSleepTime(500); vv.setGraphMouse(new DefaultModalGraphMouse<VertexTopology, Number>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.setForeground(Color.white); FontMetrics fm = vv.getFontMetrics(vv.getFont()); int width = fm.stringWidth(g.toString()); Transformer<VertexTopology, Shape> vertexSize = new Transformer<VertexTopology, Shape>() { public Shape transform(VertexTopology i) { Ellipse2D circle = new Ellipse2D.Double(-20, -20, 40, 40); // in this case, the vertex is twice as large return circle; } }; vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller() { @Override public String transform(Object v) { return ((VertexTopology) v).getScreenName(); } }); vv.getRenderContext().setVertexShapeTransformer(vertexSize); //Get picked states final PickedState<VertexTopology> pickedState = vv.getPickedVertexState(); pickedState.addItemListener(new ItemListener() { ArrayList<TestCase> outputTestCase = new ArrayList<TestCase>(); final Map<String, JButton> createdBtns = new HashMap<String, JButton>(); Map<String, Integer> deviceSelected = new HashMap<String, Integer>(); // not useful ArrayList<String> endPointList = new ArrayList<String>(); @Override public void itemStateChanged(ItemEvent e) { // TODO Auto-generated method stub Object subject = e.getItem(); if (e.getStateChange() != 1) { scaleGrids.removeAll(); filteredGrids.removeAll(); endPointList.remove(getScreenName(subject)); outputTestCase.clear(); filteredGrids.repaint(); filteredGrids.add(new JLabel(" Filtered Cases ")); filteredGrids.add(new JLabel(" ")); scaleGrids.repaint(); scaleGrids.add(new JLabel(" Test Cases ")); scaleGrids.add(new JLabel(" ")); deviceSelected.clear(); } if (e.getStateChange() == 1) { for (TestCase testCase : outputTestCase) { scaleGrids.removeAll(); scaleGrids.add(new JLabel(" Test Cases ")); scaleGrids.add(new JLabel(" ")); filteredGrids.removeAll(); filteredGrids.add(new JLabel(" Filtered Cases ")); filteredGrids.add(new JLabel(" ")); } if (subject instanceof VertexTopology) { final VertexTopology edgePicked = (VertexTopology) subject; if (pickedState.isPicked(edgePicked)) { for (TestCase testCase : edgePicked.getTestCaseList()) { if (!outputTestCase.contains(testCase)) outputTestCase.add(testCase); System.out.println("The size for reference is " + testCase.inputReferenceMap.size() + testCase.getName()); System.out.println("The size for target is " + testCase.inputTargetMap.size() + testCase.getName()); } if (deviceSelected.get(edgePicked.getScreenName()) != null) deviceSelected.put(edgePicked.getScreenName(), deviceSelected.get(edgePicked.getScreenName()) + 1); else deviceSelected.put(edgePicked.getScreenName(), 1); endPointList.add(edgePicked.getScreenName()); } } } for (TestCase testCase : outputTestCase) { JButton btnCase = new JButton(testCase.getName()); scaleGrids.add(btnCase); if (testCase.getInputDeviceList().size() <= endPointList.size()) if (testCaseSelected(testCase, endPointList)) { JButton btnCaseFiltered = new JButton(testCase.getName()); filteredGrids.add(btnCaseFiltered); } ; } scaleGrids.revalidate(); scaleGrids.setVisible(true); } }); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); content.setPreferredSize(new Dimension(1400, 900)); content.add(vv); switchLayout = new JButton("Switch to SpringLayout"); // switchLayout.addActionListener(new ActionListener() { // // @SuppressWarnings("unchecked") // public void actionPerformed(ActionEvent ae) { // Dimension d = new Dimension(600,600); // if (switchLayout.getText().indexOf("Spring") > 0) { // switchLayout.setText("Switch to FRLayout"); // layout = new SpringLayout<String,Number>(g, // new ConstantTransformer(EDGE_LENGTH)); // layout.setSize(d); // vv.getModel().setGraphLayout(layout, d); // } else { // switchLayout.setText("Switch to SpringLayout"); // layout = new FRLayout<String,Number>(g, d); // vv.getModel().setGraphLayout(layout, d); // } // } // }); JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, totalCasesPanel, filteredCasesPanel); jSplitPane.setResizeWeight(.5d); content.add(switchLayout, BorderLayout.SOUTH); content.add(jSplitPane, BorderLayout.EAST); }
From source file:main.java.gui.java
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner Evaluation license - BOHDAN Korinnyi test = new JFrame(); label1 = new JLabel(); textField1 = new JTextField(); label2 = new JLabel(); textField2 = new JTextField(); label3 = new JLabel(); label4 = new JLabel(); textField3 = new JTextField(); textField4 = new JTextField(); button1 = new JButton(); button2 = new JButton(); label5 = new JLabel(); label6 = new JLabel(); //======== test ======== {//from www .j a v a 2 s . co m test.setTitle("Pay mobile account"); Container testContentPane = test.getContentPane(); testContentPane.setLayout(null); //---- label1 ---- label1.setText("\u0421\u0443\u043c\u0430"); label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 4f)); testContentPane.add(label1); label1.setBounds(new Rectangle(new Point(35, 30), label1.getPreferredSize())); //---- textField1 ---- textField1.setColumns(10); testContentPane.add(textField1); textField1.setBounds(150, 30, 105, textField1.getPreferredSize().height); //---- label2 ---- label2.setText("\u041d\u043e\u043c\u0435\u0440"); label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 4f)); testContentPane.add(label2); label2.setBounds(new Rectangle(new Point(35, 60), label2.getPreferredSize())); //---- textField2 ---- textField2.setText("0674060606"); textField2.setFont(textField2.getFont().deriveFont(textField2.getFont().getSize() + 2f)); testContentPane.add(textField2); textField2.setBounds(150, 60, 105, textField2.getPreferredSize().height); //---- label3 ---- label3.setText("\u041b\u043e\u0433\u0456\u043d"); label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 4f)); testContentPane.add(label3); label3.setBounds(new Rectangle(new Point(35, 95), label3.getPreferredSize())); //---- label4 ---- label4.setText("\u041f\u0430\u0440\u043e\u043b\u044c"); label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 4f)); testContentPane.add(label4); label4.setBounds(new Rectangle(new Point(35, 125), label4.getPreferredSize())); testContentPane.add(textField3); textField3.setBounds(150, 95, 105, textField3.getPreferredSize().height); testContentPane.add(textField4); textField4.setBounds(150, 125, 105, 20); //---- button1 ---- button1.setText("\u041e\u043f\u043b\u0430\u0442\u0438\u0442\u0438"); button1.setFont(button1.getFont().deriveFont(button1.getFont().getStyle() | Font.BOLD, button1.getFont().getSize() + 2f)); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String strTemp = textField1.getText(); int cash = Integer.parseInt(strTemp); if (cash < 1) { JOptionPane.showMessageDialog(null, " '", "", JOptionPane.OK_OPTION); textField1.setText("0"); } else if (textField3.getText().equals("test4") && textField4.getText().equals("12345")) { check c = new check(); pay p = new pay(); getstatus g = new getstatus(); try { c.connection(c.PaymentCollectionRequest("38" + getNumber(), getMoney())); g.connection(c.PaymentStatusRequest()); p.connection(c.PaymentCollectionRequest("38" + getNumber(), getMoney())); g.connection(c.PaymentStatusRequest()); information i = new information(); daoImplements h = new daoImplements(); long curTime = System.currentTimeMillis(); String curStringDate = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(curTime); i.setIdTransaction(getTransaction.setGetTransaction()); i.setData(curStringDate); i.setNumber(Integer.parseInt(getNumber())); i.setSuma(Integer.parseInt(getMoney())); i.setStatus(parserStatus.getStatusParsing()); h.addInfo(i); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ParseException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, " ", "", JOptionPane.OK_OPTION); System.exit(0); } } }); testContentPane.add(button1); button1.setBounds(150, 155, 115, 25); //---- button2 ---- button2.setText("\u0406\u0441\u0442\u043e\u0440\u0456\u044f"); button2.setFont(button2.getFont().deriveFont(button2.getFont().getStyle() | Font.BOLD, button2.getFont().getSize() + 2f)); button2.setActionCommand("\u0406\u0441\u0442\u043e\u0440\u0456\u044f"); button2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tableData t = new tableData(); } }); testContentPane.add(button2); button2.setBounds(15, 155, 115, 25); //---- label5 ---- label5.setText( "\u0422\u0435\u0441\u0442\u043e\u0432\u0438\u0439 \u0441\u0435\u0440\u0432\u0456\u0441 \u043f\u043e\u043f\u043e\u0432\u043d\u0435\u043d\u043d\u044f \u043c\u043e\u0431\u0456\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0445\u0443\u043d\u043a\u0443"); label5.setFont(label5.getFont().deriveFont(label5.getFont().getStyle() & ~Font.ITALIC)); testContentPane.add(label5); label5.setBounds(15, 0, 255, 20); //---- label6 ---- label6.setText("38"); label6.setFont(label6.getFont().deriveFont(label6.getFont().getSize() + 4f)); testContentPane.add(label6); label6.setBounds(new Rectangle(new Point(130, 60), label6.getPreferredSize())); { // compute preferred size Dimension preferredSize = new Dimension(); for (int i = 0; i < testContentPane.getComponentCount(); i++) { Rectangle bounds = testContentPane.getComponent(i).getBounds(); preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); } Insets insets = testContentPane.getInsets(); preferredSize.width += insets.right; preferredSize.height += insets.bottom; testContentPane.setMinimumSize(preferredSize); testContentPane.setPreferredSize(preferredSize); } test.pack(); test.setLocationRelativeTo(test.getOwner()); } // JFormDesigner - End of component initialization //GEN-END:initComponents }