Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Test/Preview Different Then Java Application
Test/Preview Different Then Java Application [message #895398] Thu, 12 July 2012 13:13 Go to next message
J Kelm is currently offline J Kelm
Messages: 1
Registered: July 2012
Junior Member
Very new to WindowsBuilder so here goes:

When I try to create the JPanel and go to preview it, the preview is exactly how I would like it to display. But when I go to run it as a Java Application, it looks completely different with the JLabel and text being placed at the top of the frame. How can I get the 2 to look the same? Here is the sample code being used:

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import java.awt.Insets;
import javax.swing.UIManager;


public class HelloWorldFrame extends JFrame {

	private JPanel contentPane;
	private JTextField textField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch (Throwable e) {
			e.printStackTrace();
		}
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					HelloWorldFrame frame = new HelloWorldFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public HelloWorldFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 800);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0};
		gbl_contentPane.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		contentPane.setLayout(gbl_contentPane);
		
		JLabel lblTest = new JLabel("Test:");
		GridBagConstraints gbc_lblTest = new GridBagConstraints();
		gbc_lblTest.insets = new Insets(0, 0, 0, 5);
		gbc_lblTest.anchor = GridBagConstraints.EAST;
		gbc_lblTest.gridx = 20;
		gbc_lblTest.gridy = 3;
		contentPane.add(lblTest, gbc_lblTest);
		
		textField = new JTextField();
		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField.gridx = 21;
		gbc_textField.gridy = 3;
		contentPane.add(textField, gbc_textField);
		textField.setColumns(10);
	}

}


Thanks!





Re: Test/Preview Different Then Java Application [message #898587 is a reply to message #895398] Thu, 26 July 2012 13:13 Go to previous message
Konstantin Scheglov is currently offline Konstantin Scheglov
Messages: 554
Registered: July 2009
Senior Member
This is expected behavior.
WindowBuilder helps you in grid-based layouts, it creates empty, virtual columns and rows.
So, you can quickly start creating UI without adding explicitly columns and rows.
Because they are empty, their size should be zero, but WindowBuilder sets at design time size to some small constant, to allow you drop components there.
But at runtime size will be zero.


Konstantin Scheglov,
Google, Inc.
Previous Topic:EMF binding question
Next Topic:How to switch to Design View
Goto Forum:
  


Current Time: Tue Jul 29 13:06:04 EDT 2014

Powered by FUDForum. Page generated in 0.06957 seconds