Hi,
I'm having some trouble trying to trying shrink my frame into a specified size. The height of can shrink to a minimum size, but the width cannot. I can't figure out the reason why.
The width is located in the MyFrame class.
Here's my code:
package 620524;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JComboBox;
import java.awt.event.*;
import a00620524.view.MyFrame;
public class MyGUI
{
public MyGUI()
{
}
public static void main(String[] args)
{
MyFrame frame = new MyFrame("Simple Calculator");
//MyFrame.DimensionSize
frame.getMinimumSize();
frame.getMinimumSize2();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
package 620524.view;
import java.awt.*;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
public class MyFrame extends JFrame
{
String[] operations = {"+", "-", "/", "x"};
public MyFrame(String title)throws HeadlessException
{
super(title);
content();
}
public void content()
{
Container c = getContentPane();
JPanel panel = new JPanel();
Font font = new Font("Arial", Font.BOLD, 28);//change font
JComboBox combo = new JComboBox(operations);
combo.setSelectedIndex(0);
panel.add(combo);
c.add(panel);
}
public Dimension getMinimumSize()
{
Dimension prefSize = getPreferredSize();
return new Dimension(200, prefSize.height);
}
/*?*/
public Dimension getMinimumSize2()
{
Dimension prefSize = getPreferredSize();
return new Dimension(200, prefSize.width);
}
}