package huffman; import java.awt.Color; import javax.swing.*; public class WindowFrame extends JFrame { public WindowFrame(String title, JPanel jp) { super(title); this.add(jp); this.getContentPane().setBackground(Color.cyan); if (System.getProperty("os.name").startsWith("Mac")) { this.setSize(450, 250); } else { this.setSize(400, 250); } // this.pack(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); // setAlwaysOnTop(true); // this.setResizable(false); this.setVisible(true); } public static void test() { JFrame f = new JFrame(); JPanel basic = new JPanel(); basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS)); basic.setBackground(Color.cyan); f.add(basic); // basic.add(Box.createVerticalGlue()); JPanel bottom = new JPanel(); bottom.setAlignmentX(CENTER_ALIGNMENT); bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS)); JButton ok = new JButton("OK"); JButton close = new JButton("Close"); bottom.add(ok); // bottom.add(Box.createRigidArea(new Dimension(5, 0))); bottom.add(close); // bottom.add(Box.createRigidArea(new Dimension(15, 0))); basic.add(bottom); JButton close2 = new JButton("Close2"); close2.setAlignmentX(CENTER_ALIGNMENT); basic.add(close2); // basic.add(Box.createRigidArea(new Dimension(0, 15))); f.setSize(300, 250); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } }