![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2005
Posts: 3
Rep Power: 0
![]() |
Contents of JPanel not displaying
Request from a humble newbie...
I have been working on a gui with, among other elements, a JPanel that serves as an active panel for asking and answering questions. To the left of this active panel is another JPanel with a JTree that is used to navigate through the questions, the presentation of which is formatted on an instance of a JPanel and passed to the active panel. I have created a method in the active panel class to which I pass this other panel with the content that I want to have displayed in the active panel. From testing the gui, I know that the panel is being properly passed and loaded into the active panel; but I can't seem to get the desired content to appear. (How do I know it is being passed properly? Well, if I maxmize the window after calling this method, the panel displays the proper information; but if I don't do this, I can see it.) I am guessing that, by maximizing the window, I am causing the program to repaint the panel and to display the information; but when I try to repaint the panel manually, it doesn't work. In short, this is the relevant code: public class ActivePanel extends JPanel { ... public ActivePanel() { BevelBorder activeBorder = new BevelBorder( 1 ); setBorder( activeBorder ); setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); add( pnlTemp ); setPreferredSize( new Dimension( 600, 600 ) ); } public void setPanel( JPanel panel ) { // Clear existing contents of the panel removeAll(); // Add the new panel add( panel ); } } public class WelcomeHandler { ... public void actionPerformed( ActionEvent e ) { if( e.getSource() == application.mainMenu.fileNew ) { ... application.activePanel.setPanel( new WelcomePanel() ); } } } public class WelcomePanel extends JPanel { // Create and lay out properties of WelcomePanel } any help for a newbie monkeying around with this stuff? |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
welcome to the forums, and use code tags next time
![]() i didn't have a close look at your code yet, but are you sure you added the jpanel to a jframe? |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Sep 2005
Posts: 3
Rep Power: 0
![]() |
sorry for the lack of tags... i'll get my brain working one of these days (if only the hamster would stay on the wheel).
when you ask about adding the jpanel to the jframe, i assume you are referring to the original jpanel. if so, the answer is yes. for instance, i can add a JLabel to the original instance of the active panel when i start the application; but then, when i click the button that invokes the welcome handler, the panel clears, but does not display the new information (unless i do something to cause the panel to repaint). are you suggesting that i add the jpanel to the jframe again after i invoke the setPanel method? thanks for such a quick response. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Sep 2005
Posts: 3
Rep Power: 0
![]() |
for anyone reading this, i have temporarily solved the problem by calling the pack() method on the JFrame. this probably violates some tenet of purist programming, but it works for the time being, so if anyone else is facing this problem, i hope this solution helps you as well.
|
|
|
|
|
|
#5 |
|
Encoder
|
why do you think pack() violates the tenet of purist programming? i am sure a lot of people must be using pack() to set their frames to a proper size.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|