Results 1 to 3 of 3
  1. #1
    h4xnoodle is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default Changing from JDesktop to JPanel contentPane

    Hi,

    I am changing from JDesktop to just a JPanel based on some event, in my 'main window'. I then attempt to setup a gridlayout and put a test label on the screen -- nothing shows. It still looks like the JDesktop contentPane is being used, since the background colour is still that of the JDesktop one. Am I missing something here?

    Java Code:
    public class MainWindow extends JFrame {
    private MainWindow() {
    	desktop = new JDesktopPane();
    	this.setContentPane(desktop);
    	desktop.setBackground(new Color(0x333333));
    	desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    	// Added a JInternalFrame, and on button push I get to constructMain() below...
    }
    
    ....
    
    private void constructMain() {
    	JPanel screen = new JPanel(new GridLayout(2,1));
    	screen.setBackground(Color.WHITE);
    	JLabel t = new JLabel("test");
    	t.setForeground(Color.BLACK);
    	screen.add(t);
    	this.setContentPane(screen);
    }
    The label does not show up, and the JFrame bg colour is still #333333

    UPDATE: doing "this.setVisible(true)" after the "this.setContentPane(screen)" works... but creates another window.
    Last edited by h4xnoodle; 06-21-2011 at 06:26 AM. Reason: Update.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    If you change the contentPane, you'll likely have to revalidate and repaint the top-level container. I have a feeling though that a lot more is going on than you're letting us see in code that you have but have not posted to the forum.

  3. #3
    h4xnoodle is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default

    Yeah, my mistake. I actually just solved it. I pulled a huge singleton-noob mistake and did not set my instance to the new instance of MainWindow. I also added a validate() -- thanks for the tip. Sleep deprivation FTL...

    Thanks :)

Similar Threads

  1. Replies: 4
    Last Post: 04-19-2011, 06:09 AM
  2. Replies: 0
    Last Post: 03-03-2011, 09:45 PM
  3. Changing an Applet to a JPanel
    By xSkittlesx in forum Java Applets
    Replies: 2
    Last Post: 05-31-2010, 04:41 PM
  4. Replies: 3
    Last Post: 02-06-2010, 04:28 PM
  5. Changing JPanel sizes
    By Basit in forum Java Applets
    Replies: 2
    Last Post: 08-12-2009, 07:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •