Results 1 to 5 of 5
Thread: JavaHelp
- 02-16-2009, 06:07 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 2
- Rep Power
- 0
JavaHelp
hi, im trying to create a java program for a assignment, in which i need four windows with buttons along the top that say, main page, client, residential and commercial, when you click one of the buttons it goes to said window, and inside i need to have panels with panels.
this is my main concern, i cant seem to figure out how to have multiple panels in one window. i need to make it so client, has a client information panel, a search panel and a results panel.
if anyone could help that would be greatly appreciated.
this is the basic code i have so far
package Assignment2;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.*;
import java.awt.*;
/*
* Author: John Stuby
* ID: 000457330
*/
public class clientWindow
{
//attributes
private JTextField textTF;
//Constructors
public JPanel createClientWindow()
{
JPanel clientPanel = new JPanel();
JLabel clientLabel = new JLabel("Client Management Screen",SwingConstants.CENTER);
clientLabel.setForeground(Color.blue);
clientLabel.setFont(new Font("Copperplate Gothic Bold",Font.BOLD,38));
clientPanel.add(clientLabel);
return clientPanel; //returns the clientPanels
}
}
- 02-16-2009, 07:58 AM #2
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
first you'll have to create a main panel separatedly and add subpanels to it and then add subpanels to the main panel. then add the main panel to the frame )
you got it?JFrame frame=new JFrame();
frame.getContentPane().add(mainpanem);
- 02-16-2009, 08:14 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 2
- Rep Power
- 0
ok, thanks, that helps a lot. :)
- 02-16-2009, 08:30 PM #4
Please go to the top of this page and click Thread Tools, and then in the drop-down Menu click Mark This Thread As Solved so no one else comes here thinking there is still a problem.
Tell me if you want a cool Java logo avatar like mine and I'll make you one.
-
The tutorials that will likely help you the most is the Sun Swing layout manager tutorial set. If you go through it and study the sample programs, you'll find arranging multiple JPanels to be a breeze. One caveat: most newbies to layouts either use the null layout and try to place components by absolute positioning or use one of the most complex layout managers, the GridBagLayout. I suggest that you not do either that you study the FlowLayout, BorderLayout, GridLayout, and BoxLayout in that order and that you nest JPanels each one using its own layout. Also look at the CardLayout which lets you easily swap JPanels or other JComponents.
Come on back if this doesn't make sense or if you try to use these but run into a snag.
Link: Laying Out Components Within A Container


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks