Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 19th, 2005, 8:56 AM   #1
PhillyRunner
Newbie
 
Join Date: Sep 2005
Posts: 3
Rep Power: 0 PhillyRunner is on a distinguished road
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?
PhillyRunner is offline   Reply With Quote
Old Sep 19th, 2005, 9:03 AM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
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?
Polyphemus_ is offline   Reply With Quote
Old Sep 19th, 2005, 9:08 AM   #3
PhillyRunner
Newbie
 
Join Date: Sep 2005
Posts: 3
Rep Power: 0 PhillyRunner is on a distinguished road
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.
PhillyRunner is offline   Reply With Quote
Old Sep 19th, 2005, 11:26 AM   #4
PhillyRunner
Newbie
 
Join Date: Sep 2005
Posts: 3
Rep Power: 0 PhillyRunner is on a distinguished road
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.
PhillyRunner is offline   Reply With Quote
Old Sep 23rd, 2005, 8:44 AM   #5
susam_pal
Encoder
 
Join Date: Sep 2005
Location: India
Posts: 12
Rep Power: 0 susam_pal is on a distinguished road
Send a message via Yahoo to susam_pal
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.
susam_pal is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:39 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC