Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with my GUI program

Status
Not open for further replies.

GarrettSF

Programmer
Jul 22, 2008
11
US
Hey guys. I have been writing this GUI for about two weeks now and have run into a snag, layouts. I has minimal GUI coding experience. I tried to learn the Gridbag layout but, it was to complex with my limited knowledge. I talked to a friend of mine who suggested using a few JPanels and using the gridlayout but still couldn't get what I wanted.

I want my GUI to look like the attached picture. I would also like to incorporate some type of help system so if someone needs some help understanding what a feature does, they can find the help right there, in the GUI. I want it to be very idiot proof/ user friendly.

What layout do you recommend for my scenario?
 
gridlayout (4,2) if you do not mind that they have the same size
 
I just want the textboxs to be smaller and the labels to alien with their corresponding components.
 
If you like to line up two components, you create a JPanel (i.e. BoxLayout.LINE_AXIS) and add Label, add JTextField.

The Panel will keep them together.

Add those JPanels to another JPanel with BoxLayout.PAGE_AXIS.
Add the big Panel to the Center of a BorderLayout, and the JButton (with its own Label (output folder)) to the NORTH.

Better: Label your Button "output folder: /path/to/current/folder".
Or left: Button, labeled 'output folder', to the right the current selection in a JLabel or JTextField.

The benefit of a JTextField is: the user might put a path with copy-and-paste there, without 10 clicks.

don't visit my homepage:
 
I like your second idea. It is a great transition into my next question. I will do you first idea for now and tweak it depending on the solution to my next question.

I need a way to graphically have the user select the path to where they would like something to exported to. What class should I use? All I need is the path name, ie: C:\Documents and Settings\GarettSF\Desktop, nothing more.
 
javax.swing.JFileChooser
You may get a file from a user and you can cut the filename and use isDirectory to check if the result file is a directory.
Use the isDirectory in Java.io.File to check
 
Code:
		outDirPanel = new JPanel();
		outDirPanel.setLayout( new BoxLayout( outDirPanel, BoxLayout.LINE_AXIS));		
		LoutputDir = new JLabel("Output Folder");
		outputDir = new JButton("Click here to set output path");
		//outputDir.addActionListener(this);
		outDirPanel.add( LoutputDir);
		outDirPanel.add( outputDir);
		
		finalNamePanel = new JPanel();
		finalNamePanel.setLayout( new BoxLayout( finalNamePanel, BoxLayout.LINE_AXIS));			
		LfinalModelName = new JLabel( "Final Name");
		TfinalModelName = new JTextField();
		finalNamePanel.add( LfinalModelName);
		finalNamePanel.add( TfinalModelName);
		
		finalSKPPanel = new JPanel();
		finalSKPPanel.setLayout( new BoxLayout( finalSKPPanel, BoxLayout.LINE_AXIS));
		LskpFileName = new JLabel( "SKP file Name" );
		TskpFileName = new JTextField();
		finalSKPPanel.add( LskpFileName);
		finalSKPPanel.add( TskpFileName);
		
		finalScenePanel = new JPanel();
		finalScenePanel.setLayout( new BoxLayout( finalScenePanel, BoxLayout.LINE_AXIS));
		LsmdSceneName = new JLabel( "smd Scene Name\n with animations" );
		TsmdSceneName = new JTextField();
		finalScenePanel.add( LsmdSceneName);
		finalScenePanel.add( TsmdSceneName);
		
		mainPanel = new JPanel();
		mainPanel.setLayout( new BoxLayout( mainPanel, BoxLayout.PAGE_AXIS));
		mainPanel.add( finalNamePanel);
		mainPanel.add( finalSKPPanel);
		mainPanel.add( finalScenePanel);
		
		mainContainer.add( outDirPanel, BorderLayout.NORTH );
		mainContainer.add( mainPanel, BorderLayout.CENTER );
 
 http://img.photobucket.com/albums/v91/4wheelingman/GUIISSUEnew.jpg
That is the code and the result. The textboxs are too big for my liking. Still don't know how to make them only one line big.

Prosper: You idea is too mess. I would like the user to be able to have the same type of screen as you would get if you are choosing the folder you would like something to be installed in using an install manager.
 
I just tell the swing class to get path from user. Other people
will not know about your feeling in choosing swing component.
 
I prefer the 3 JTextFields have the same width.
The 3 JLabels on the left may have the same width and the width may be different from the JTextField.
 
How would I specify the label's and the textbox's width so I can make the textboxes smaller?
 
Try putting the Panel with GridLayout into JFlowLayout and add them to the frame
 
Little example for JFileChooser, selecting only directories:

Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class Demo extends JFrame implements ActionListener
{
	public JButton b;
	public JTextField t;

	public static void main(String args[])
	{
		new Demo();
	}

	public Demo()
	{
		b = new JButton("Click me");
		t = new JTextField();

		Container c = this.getContentPane();
		c.setLayout(new GridLayout(1,2));
		c.add(b);
		c.add(t);
		b.addActionListener(this);
		this.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent we)
			{
				System.exit(0);
			}
		});
		this.pack();
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}

	public void actionPerformed(ActionEvent ae)
	{
		Object source = ae.getSource();
		if (source == b)
		{
			[b]JFileChooser jfc = new JFileChooser();
			jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			int ret = jfc.showOpenDialog(null);
			if (ret == JFileChooser.APPROVE_OPTION)[/b]
			{
				File f = jfc.getSelectedFile();
				JOptionPane.showMessageDialog(null,"You've selected directory " + f.getName(), "Info", JOptionPane.INFORMATION_MESSAGE);
				t.setText(f.getName());
			}
			else
			{
				JOptionPane.showMessageDialog(null,"You haven't selected any directory", "Info", JOptionPane.WARNING_MESSAGE);
				t.setText("");
			}
		}
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top