Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java frame resize in GUI

807605Jul 19 2007 — edited Jul 21 2007
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);
	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 18 2007
Added on Jul 19 2007
12 comments
966 views