Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » I'm having trouble with alignment in the window builder. controls Wont snap into place. (Designing a GUI with windowbuilder)
I'm having trouble with alignment in the window builder. controls Wont snap into place. [message #1694959] Sun, 10 May 2015 21:23
apache omega is currently offline apache omegaFriend
Messages: 1
Registered: May 2015
Junior Member
Hello All!!!
I'm new to Java and eclipse and everything is going quite well, the only problem I'm having right now is aligning my controls where I want them. I'm unfortunately spoiled by the ease of using C# .net controls so I guess I got some learning to do as far as Java goes.
This is what I have going on in my view Panel.
As you can see I got stuff all over the place and everytime I run the design panel it dumps all this crap after my baseLayout = new SpringLayout(); method.

Here's the Code, also I uploaded an image of what I'm dealing with.

package tsd.view;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
import tsd.controller.TsdAppController;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;

public class TsdPanel extends JPanel 
{
	private TsdAppController baseController;
	private JLabel nameLabel;
	private JLabel descriptionLabel;
	private JLabel weightLabel;
	private JLabel sizeLabel;
	private JTextField nameField;
	private JTextField descriptionField;
	private JTextField sizeField;
	private JTextField weightField;
	private JButton createWidgetButton;
	private JButton createWhatsitButton;
	private SpringLayout baseLayout;
	
	public TsdPanel(TsdAppController baseController)
	{
		this.baseController = baseController;
		
		nameLabel = new JLabel("type the name of the Whatsit");
		descriptionLabel = new JLabel("Describe the Widget");
		weightLabel = new JLabel("Enter the weight for the widget");
		sizeLabel = new JLabel("Enter the size of the Whatsit");
		
		nameField = new JTextField(15);
		descriptionField = new JTextField(15);
		weightField = new JTextField(10);
		sizeField = new JTextField(10);
		
		createWidgetButton = new JButton("Make a Widget");
		createWhatsitButton =new JButton("Make a Whatsit");
		
		baseLayout = new SpringLayout();
		
		setupPanel();
		setupLayout();
		setupListeners();
		
	}
	
	private void setupLayout()
	{
		baseLayout.putConstraint(SpringLayout.NORTH, nameLabel, 117, SpringLayout.NORTH, this);
		baseLayout.putConstraint(SpringLayout.EAST, nameLabel, -10, SpringLayout.EAST, this);
		baseLayout.putConstraint(SpringLayout.NORTH, descriptionField, 0, SpringLayout.NORTH, nameField);
		baseLayout.putConstraint(SpringLayout.WEST, descriptionField, 10, SpringLayout.WEST, this);
		baseLayout.putConstraint(SpringLayout.EAST, descriptionField, -11, SpringLayout.EAST, this);
		baseLayout.putConstraint(SpringLayout.SOUTH, sizeLabel, -41, SpringLayout.NORTH, weightField);
		baseLayout.putConstraint(SpringLayout.NORTH, weightLabel, 0, SpringLayout.NORTH, sizeLabel);
		baseLayout.putConstraint(SpringLayout.WEST, weightLabel, 0, SpringLayout.WEST, createWidgetButton);
		baseLayout.putConstraint(SpringLayout.WEST, sizeLabel, 0, SpringLayout.WEST, nameField);
		baseLayout.putConstraint(SpringLayout.EAST, createWhatsitButton, -31, SpringLayout.EAST, this);
		baseLayout.putConstraint(SpringLayout.WEST, nameField, 260, SpringLayout.WEST, this);
		baseLayout.putConstraint(SpringLayout.NORTH, createWidgetButton, 0, SpringLayout.NORTH, createWhatsitButton);
		baseLayout.putConstraint(SpringLayout.WEST, createWidgetButton, 10, SpringLayout.WEST, this);
		baseLayout.putConstraint(SpringLayout.NORTH, sizeField, 0, SpringLayout.NORTH, weightField);
		baseLayout.putConstraint(SpringLayout.WEST, sizeField, 10, SpringLayout.WEST, this);
		baseLayout.putConstraint(SpringLayout.NORTH, createWhatsitButton, 395, SpringLayout.NORTH, this);
		baseLayout.putConstraint(SpringLayout.SOUTH, weightField, -33, SpringLayout.NORTH, createWhatsitButton);
		baseLayout.putConstraint(SpringLayout.EAST, weightField, 0, SpringLayout.EAST, createWhatsitButton);
		baseLayout.putConstraint(SpringLayout.EAST, nameField, -31, SpringLayout.EAST, this);
		baseLayout.putConstraint(SpringLayout.NORTH, nameField, 94, SpringLayout.SOUTH, nameLabel);
		
	}
	
	private void setupPanel()
	{
		this.setSize(500, 500);
		this.setLayout(baseLayout);
		this.add(createWhatsitButton);
		this.add(createWidgetButton);
		this.add(descriptionField);
		this.add(nameField);
		this.add(sizeField);
		this.add(weightField);
		this.add(descriptionField);
		this.add(nameLabel);
		this.add(sizeLabel);
		this.add(weightLabel);
		this.add(descriptionLabel);
		
	}
	
	private void setupListeners()
	{
		
	}
}



Previous Topic:How to Contruct GUI
Next Topic:[Solved] Custom widget rendering
Goto Forum:
  


Current Time: Tue Sep 25 23:41:17 GMT 2018

Powered by FUDForum. Page generated in 0.01970 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top