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 Swing Jpanel display problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing Jpanel display problem" Watch "Swing Jpanel display problem" New topic
Author

Swing Jpanel display problem

Ben Koh
Greenhorn

Joined: Aug 06, 2001
Posts: 7
Dear Java Gurus, I have a jtabbedpanel which is contained inside a frame. Each tab of the tabbedpanel contains a component to be displayed. There are a total of 3 tabs and thus 3 total components. The problem arises when i run the frame after compiling. Each tab's display is not working properly but only works after clicking through all the tabs a couple of times. The code below lists a component out of the total 3 similar ones that is to be displayed. I am wondering could it be because of overusing arrays for each panel. Please kindly enlighten me. Thanks!

protected Component buildBookingPanel() {
// main panel
JPanel mainPanel = new JPanel();
// divided into three panes. these panes will be added to mainPanel
JPanel westPane = new JPanel();
JPanel centrePane = new JPanel();
JPanel southPane = new JPanel();
// assign the layout managers
mainPanel.setLayout(new BorderLayout());
westPane.setLayout(new GridLayout(12,1));
centrePane.setLayout(new GridLayout(12,1));
// create array of Panels for label textfield and buttons and make them left align
Panel labelPane[] = new Panel[12];
Panel textPane[] = new Panel[12];
Panel buttonPane[] = new Panel[2];
for (int i=0; i < labelPane.length; ++i) {
labelPane[i] = new Panel();
labelPane[i].setLayout(new FlowLayout(FlowLayout.LEFT));
}
for (int i=0; i < textPane.length; ++i) {
textPane[i] = new Panel();
textPane[i].setLayout(new FlowLayout(FlowLayout.LEFT));
}
for (int i=0; i < buttonPane.length; ++i) {
buttonPane[i] = new Panel();
buttonPane[i].setLayout(new FlowLayout(FlowLayout.LEFT));
}

// add different label to the labelPane
labelPane[0].add(new JLabel("Booking Number"));
labelPane[1].add(new JLabel("Movie Code"));
labelPane[2].add(new JLabel("Name"));
labelPane[3].add(new JLabel("NRIC"));
labelPane[4].add(new JLabel("Telephone"));
labelPane[5].add(new JLabel("Credit Card Number"));
labelPane[6].add(new JLabel("Quantity"));
labelPane[7].add(new JLabel("Booking Date"));
labelPane[8].add(new JLabel("Showtime"));
labelPane[9].add(new JLabel("Location"));
labelPane[10].add(new JLabel("Theatre Number"));
labelPane[11].add(new JLabel("Price"));
// add textfield component to textPane
GetBookingNo();
textPane[0].add(BookingNo);
textPane[0].add(findButton);
findButton.setMnemonic('f');
textPane[1].add(MovieCode);
textPane[2].add(Name);
textPane[3].add(NRIC);
textPane[4].add(Telephone);
textPane[5].add(CreditCard);
Quantity.setEditable(false);
textPane[6].add(Quantity);
Quantity.setText(""+test);
textPane[6].add(UpdateSeatsButton);
BookingDate.setText(new java.util.Date().toString());
textPane[7].add(BookingDate);
textPane[8].add(ShowTime);
textPane[9].add(Location);
textPane[10].add(TheatreNo);
Price.setEditable(false);
textPane[11].add(Price);
textPane[11].add(new JLabel("NOTE: Price Will Be Automatically Calculated"));
// add button to buttonPane
buttonPane[0].add(OkButton);
OkButton.setMnemonic('o');
buttonPane[0].add(updateButton);
updateButton.setMnemonic('u');
updateButton.setEnabled(false);
buttonPane[0].add(deleteButton);
deleteButton.setMnemonic('d');
deleteButton.setEnabled(false);
buttonPane[0].add(ListAllBookingButton);
deleteButton.setMnemonic('l');
buttonPane[0].add(clearButton);
deleteButton.setMnemonic('c');
// add actionlistener to the buttons
OkButton.addActionListener(new ButtonHandler());
findButton.addActionListener(new ButtonHandler());
updateButton.addActionListener(new ButtonHandler());
deleteButton.addActionListener(new ButtonHandler());
clearButton.addActionListener(new ButtonHandler());
UpdateSeatsButton.addActionListener(new ButtonHandler());
ListAllBookingButton.addActionListener(new ButtonHandler());

for (int i = 0; i < labelPane.length; ++i)
westPane.add(labelPane[i]);
for (int i = 0; i < textPane.length; ++i)
centrePane.add(textPane[i]);
for (int i = 0; i < buttonPane.length; ++i)
southPane.add(buttonPane[i]);
mainPanel.add(westPane,BorderLayout.WEST);
mainPanel.add(centrePane,BorderLayout.CENTER);
mainPanel.add(southPane,BorderLayout.SOUTH);


return mainPanel;
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Swing Jpanel display problem
 
Similar Threads
Need suggestion reg Layout Managers
Unable to Launch JWS A[pplication
Too many ActionEvents after button press.
change text on jtextfield from one class after clicking submit from another class
adding components to JPanel