Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Advice  RSS feed

 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi;

I am trying creating a swing application. Basically the client connects to a database and than is giving various options for customizing and creating reports with different views of the data.

My first idea was to use the JTabbedPane. Each tab would be associated with a pane. The method that creates the pane would create its contents depending on whether the client was connected or not when they clicked the tab.

I thought I could create a ChangeListener class and add it to my JTabbedPane. Everytime you changed tabs it would regenerate all the panels associated with each tab and than repaint the JTabbedPane. Thus all the interfaces would be constantly refreshed with current data (or nothing if they are not connected to the database).

The problem is the view of the panel never changes from when it was first created.

Here is my method that handles tab changes:

class TabListener implements ChangeListener {

/*
* Each time someone clicks a tab recreate all the panels
* and redraw the tabbedpane to refresh all the views.
* once this works refine it to only redraw the panel
* that is selected
*/
public void stateChanged(ChangeEvent e) {
//create the panels again
createMainPane();
createAuctioneerDataPane();
createAuctionDataPane();
createAuctionPane();
createAuctioneerPane();
createUpdatePane();
//repaint the tabbedpane
tabs.repaint();
}

}

Is there a better way to do this? Anyone ever done anything like this before?

Thanks,

Luke
 
Sainath Veepuri
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Luke,
Originally posted by Luke Shannon:
Hi;

I am trying creating a swing application. Basically the client connects to a database and than is giving various options for customizing and creating reports with different views of the data.

My first idea was to use the JTabbedPane. Each tab would be associated with a pane. The method that creates the pane would create its contents depending on whether the client was connected or not when they clicked the tab.

I thought I could create a ChangeListener class and add it to my JTabbedPane. Everytime you changed tabs it would regenerate all the panels associated with each tab and than repaint the JTabbedPane. Thus all the interfaces would be constantly refreshed with current data (or nothing if they are not connected to the database).

The problem is the view of the panel never changes from when it was first created.

Here is my method that handles tab changes:

class TabListener implements ChangeListener {

/*
* Each time someone clicks a tab recreate all the panels
* and redraw the tabbedpane to refresh all the views.
* once this works refine it to only redraw the panel
* that is selected
*/
public void stateChanged(ChangeEvent e) {
//create the panels again
createMainPane();
createAuctioneerDataPane();
createAuctionDataPane();
createAuctionPane();
createAuctioneerPane();
createUpdatePane();
//repaint the tabbedpane
tabs.repaint();
}

}

Is there a better way to do this? Anyone ever done anything like this before?

Thanks,

Luke


You might need to call tabs.validate or whereever is required, if the components are reorganized or modified or if the layout is changed. This should change the previous view.
If it still doesnot work, would you post your code to have a glance?
- Sai
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sai;

Good call. That works perfectly. Thanks for the help.

Luke
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!