• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing Jpanel display problem

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
reply
    Bookmark Topic Watch Topic
  • New Topic