File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes organising panels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "organising panels" Watch "organising panels" New topic
Author

organising panels

Ariane Bogain
Greenhorn

Joined: Apr 25, 2003
Posts: 15
I'm trying to polish off my GUI but I have several problems:
1 - The initial screen has two buttons booking and quit. When the user click booking other buttons appears with labels and textbox. The problem I'm having is that these new buttons do not appear, I have to maximise the window for them to appear.

2 - I created several panels so that each textbox and labels appear underneath each other but that doesn't work as they appear a bit all over the place!
My code is the following:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class Jobs extends Panel implements ActionListener
{
private Button booking=new Button("make a booking");
private TextField staff=new TextField (10);
private TextField jbcode = new TextField(4);
private TextField Startdate = new TextField(6);
private TextField Enddate = new TextField(6);
private TextField jobs=new TextField(1);
private Label jobt=new Label("Enter the job type");
private Label id = new Label ("Enter your staff id");
private Label jobcode=new Label("Enter the code of your job");
private Panel position=new Panel();
private Panel staffid=new Panel();
private Panel codepanel=new Panel();
private Panel sub= new Panel();
private Panel sedate=new Panel();
private Panel jobtype=new Panel();
private Panel d=new Panel();
private Label type= new Label ("Choose productive or non productive to submit the details");
private Label date=new Label("Enter the startdate of your job (e.g.30/APR/03)");
private Label ndate=new Label("Enter the end date of your job (e.g.30/MAY/03)");
private Button quitbutton=new Button ("Quit the booking system");
private Button submit = new Button ("Submit your booking");
public Jobs (){

position.setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
position.add(booking);
position.add(quitbutton);
add(position);
booking.addActionListener(this);
quitbutton.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{if (e.getSource() == booking)
{
staffid.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
staffid.add(staff);
staffid.add(id);
add(staffid);
codepanel.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
codepanel.add(jbcode);
codepanel.add(jobcode);
add(codepanel);
d.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
d.add(date);
d.add(Startdate);
add(d);
sedate.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
sedate.add(ndate);
sedate.add(Enddate);
add(sedate);
jobtype.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
jobtype.add(jobt);
jobtype.add(jobs);
add(jobtype);
sub.setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
sub.add(submit);
add(sub);
submit.addActionListener(this);
}
Could anyone tell me what I'm doing wrong?
Thank you very much!
Dorothy Finkel-Laverty
Ranch Hand

Joined: Nov 24, 2001
Posts: 51
I might have missed it, but I did not see you call pack(). When you pack your JFrame or Frame, you let the layout manager do its job - that is, resize the container and paint the components onto it.
Add a call to frame.pack() and see if that does the trick.
Ariane Bogain
Greenhorn

Joined: Apr 25, 2003
Posts: 15
Where should I put this call to frame pack? I've tried to put it like this:
import java.awt.*;
public class Log{
public static void main(String[] args)
{Frame frame=new Frame();
frame.pack();
frame.setTitle("Password");
Jobs test=new Jobs();
frame.setSize(700,700);
frame.setBackground(Color.lightGray);
frame.add(test);
frame.setVisible(true);

}
}
but I still have to maximise and minimise the window to have the new elements appearing!
 
GeeCON Prague 2014
 
subject: organising panels