Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-29-2011, 03:14 PM   PM User | #1
dethtrain
New to the CF scene

 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dethtrain is an unknown quantity at this point
Not sure why my buttons aren't showing (swing)

I've essentially copied a layout from a previous assignment I wrote, and everything displays fine. I'm splitting the main window up in 2 parts using BorderLayout as the layout manager for the frame. Then I pop a JPanel in the north spot and another one in the center. Most of my buttons, labels and components are in the north panel. But they don't display! I'm not sure what I am missing (but I have a feeling it's something stupid)

Code:
public class HouseHoldBudget extends JFrame {
	private JPanel 		northPanel;
	private JPanel 		centerPanel;
	private JPanel 		mainPane;
	private JButton		enterNameAndStartBalanceButton;
	private	JButton		calculateProjectionButton;
	private JLabel		nameLabel;
	private JTextArea	nameTextArea;
	private	JLabel		startBalanceLabel;
	private JTextArea	startBalanceTextArea;
	private JTable		mainTable;
	private JButton		openFileButton;
	private	JButton		writeFileButton;
	
	public HouseHoldBudget()
	{
		super("Household Budget");
		northPanel = new JPanel(new SpringLayout());
		centerPanel = new JPanel();
		mainPane = new JPanel(new BorderLayout());
		enterNameAndStartBalanceButton = new JButton("Enter name/start Balance");
		calculateProjectionButton = new JButton("Calculate Projection");
		nameLabel = new JLabel("Name:");
		nameTextArea = new JTextArea();
		mainTable = new JTable();
		openFileButton = new JButton("Open");
		writeFileButton = new JButton("Write");
		this.setLayout(new BorderLayout());
		this.setFocusable(true);
		this.setSize(1024, 800);
		this.setResizable(false);
		
		layoutGUI();
		
	}
	
	private void layoutGUI()
	{
		setupNorthPanel();
		setupCenterPanel();
		this.add(centerPanel, BorderLayout.CENTER);
		this.add(northPanel, BorderLayout.NORTH);
		
	}
	
	private void setupNorthPanel()
	{
		SpringLayout layout = (SpringLayout) northPanel.getLayout();
		layout.putConstraint(SpringLayout.WEST, enterNameAndStartBalanceButton, 5, SpringLayout.WEST, northPanel);
		layout.putConstraint(SpringLayout.NORTH, enterNameAndStartBalanceButton, 5, SpringLayout.NORTH, northPanel);
		layout.putConstraint(SpringLayout.WEST, calculateProjectionButton, 5, SpringLayout.EAST, enterNameAndStartBalanceButton);
		layout.putConstraint(SpringLayout.NORTH, calculateProjectionButton, 5, SpringLayout.NORTH, northPanel);
		layout.putConstraint(SpringLayout.WEST, openFileButton, 5, SpringLayout.EAST, calculateProjectionButton);
		layout.putConstraint(SpringLayout.NORTH, openFileButton, 5, SpringLayout.NORTH, northPanel);
		layout.putConstraint(SpringLayout.WEST, writeFileButton, 5, SpringLayout.EAST, openFileButton);
		layout.putConstraint(SpringLayout.NORTH, writeFileButton, 5, SpringLayout.NORTH, northPanel);
		layout.putConstraint(SpringLayout.WEST, nameLabel, 0, SpringLayout.HORIZONTAL_CENTER, northPanel);
		layout.putConstraint(SpringLayout.NORTH, nameLabel, 0, SpringLayout.NORTH, northPanel);
		layout.putConstraint(SpringLayout.WEST, nameTextArea, 5, SpringLayout.EAST, nameLabel);
		layout.putConstraint(SpringLayout.NORTH, nameTextArea, 0, SpringLayout.NORTH, northPanel);
		
		northPanel.add(enterNameAndStartBalanceButton);
		northPanel.add(calculateProjectionButton);
		northPanel.add(openFileButton);
		northPanel.add(writeFileButton);
		northPanel.add(nameLabel);
		northPanel.add(nameTextArea);
		northPanel.setSize(1024, 200);
		northPanel.setBackground(Color.BLACK);
	}
	
	public void setupCenterPanel()
	{
		JScrollPane jsp = new JScrollPane(mainTable);
		centerPanel.add(jsp);
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		HouseHoldBudget window = new HouseHoldBudget();
		window.setVisible(true);
	}

}
Nevermind, I changed setSize to setPreferredSize. So annoying.

Last edited by dethtrain; 04-29-2011 at 03:16 PM..
dethtrain is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:55 PM.


Advertisement
Log in to turn off these ads.