public MainFrame() { try { mainPanel.setLayout(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9)); mainPanel.add(outputContainer, java.awt.BorderLayout.CENTER); outputArea.setLineWrap(true); outputContainer.add(new JScrollPane(outputArea), java.awt.BorderLayout.CENTER); outputContainer.setBorder(new javax.swing.border.TitledBorder("Results")); this.getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER); java.util.ArrayList<JButton> btns = new java.util.ArrayList<JButton>(); { JPanel westPanel = new JPanel(new GridLayout(0, 1, 0, 10)); westPanel.setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9)); JPanel opsPanel = new JPanel(new GridLayout(6, 1)); opsPanel.setBorder(new javax.swing.border.TitledBorder("Operations")); for (Action action : operations) { JPanel p = new JPanel(new BorderLayout()); JButton jb = new JButton(action); btns.add(jb); p.add(jb, BorderLayout.NORTH); opsPanel.add(p); } westPanel.add(opsPanel); controlContainer.add(westPanel, BorderLayout.CENTER); } this.getContentPane().add(controlContainer, BorderLayout.WEST); this.pack(); Dimension dim = btns.get(0).getSize(); for (JButton btn : btns) { btn.setPreferredSize(dim); } java.awt.Dimension prefSize = this.getPreferredSize(); prefSize.setSize(prefSize.getWidth(), 1.1 * prefSize.getHeight()); this.setSize(prefSize); java.awt.Dimension parentSize; java.awt.Point parentLocation = new java.awt.Point(0, 0); parentSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); int x = parentLocation.x + (parentSize.width - prefSize.width) / 2; int y = parentLocation.y + (parentSize.height - prefSize.height) / 2; this.setLocation(x, y); this.setResizable(true); } catch (Exception e) { e.printStackTrace(); } }
public void actionPerformed(ActionEvent actionEvent) { outputArea.setText(""); GLFrame glFrame = new GLFrame(outputArea); glFrame.setVisible(true); }