fshtank
asked on
SWING: Replace a JFrame's pre-existing JPanel with a different JPanel
Hi everyone,
I have a selection list that will drive the contents of a particular JPanel.
This window is in MS Outlook / E-mail format (3 sections):
1) vertical list
2) Selection Criteria (Search)
3) Output Results
Mouse click a JList item (section #1) to put the appropriate search criteria options in the JPanel.
I have created a separate external JPanel object for each criteria setup.
Code:
private void lstReportListMouseClicked( java.awt.e vent.Mouse Event evt) {
idx = lstReportList.getSelectedI ndex()
. . . get clicked objects String Value . . .
if (stringVal.equals("Next Chosen Criteria")) {
// I want to replace the current Criteria JPanel (Section #2) with the new Corresponding JPanel here.
// I have tried the Following:
panelrptCriteria.add(new nextCriteriaPanel());
panelrptCriteria = new nextCriteriaPanel();
}
}
The Jpanel does not refresh correctly to show the search options.
What do I need to do here? I am stuck.
I am using Matisse with MyEclipseIDE to generate the SWING code. The code above is my own custom code in a JList event.
Thanks for your help.
I have a selection list that will drive the contents of a particular JPanel.
This window is in MS Outlook / E-mail format (3 sections):
1) vertical list
2) Selection Criteria (Search)
3) Output Results
Mouse click a JList item (section #1) to put the appropriate search criteria options in the JPanel.
I have created a separate external JPanel object for each criteria setup.
Code:
private void lstReportListMouseClicked(
idx = lstReportList.getSelectedI
. . . get clicked objects String Value . . .
if (stringVal.equals("Next Chosen Criteria")) {
// I want to replace the current Criteria JPanel (Section #2) with the new Corresponding JPanel here.
// I have tried the Following:
panelrptCriteria.add(new nextCriteriaPanel());
panelrptCriteria = new nextCriteriaPanel();
}
}
The Jpanel does not refresh correctly to show the search options.
What do I need to do here? I am stuck.
I am using Matisse with MyEclipseIDE to generate the SWING code. The code above is my own custom code in a JList event.
Thanks for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html
ASKER
Card layout would have me instantiate each JPanel at construction and then set visible(true/false) as needed correct?
That seems kind of heavy. The intention of this list is for it to grow - so if I have up to 10 even 20 search options, that seems a bit 'big.'
I tried revalidate and it didn't cause the JPanel to be drawn.
I also tried repaint on the window itself - that also did not draw the JPanel.
if (stringVal.equals("Next Chosen Criteria")) {
panelrptCriteria = new nextCriteriaPanel();
}
panelrptCriteria.setVisibl e(true);
panelrptCriteria.revalidat e();
this.repaint(); // repaint the JFrame
Any other thoughts?
- Thanks
That seems kind of heavy. The intention of this list is for it to grow - so if I have up to 10 even 20 search options, that seems a bit 'big.'
I tried revalidate and it didn't cause the JPanel to be drawn.
I also tried repaint on the window itself - that also did not draw the JPanel.
if (stringVal.equals("Next Chosen Criteria")) {
panelrptCriteria = new nextCriteriaPanel();
}
panelrptCriteria.setVisibl
panelrptCriteria.revalidat
this.repaint(); // repaint the JFrame
Any other thoughts?
- Thanks
> Card layout would have me instantiate each JPanel at construction and then set visible(true/false) as needed correct?
you'd create them up front, but use the show() method of the layout manager not setVisible()
> That seems kind of heavy.
not really, you'll find creating/adding/removing panels as required is going to put more load on your app
> panelrptCriteria.revalidat e();
u need to revalidate() the panel you are adding to, not the panel you added.
you'd create them up front, but use the show() method of the layout manager not setVisible()
> That seems kind of heavy.
not really, you'll find creating/adding/removing panels as required is going to put more load on your app
> panelrptCriteria.revalidat
u need to revalidate() the panel you are adding to, not the panel you added.
ASKER
This will simplify things in the short term.
Thanks.
Thanks.