Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By camickr

Thread: JdesktopPane

  1. #1
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Posts
    38
    Rep Power
    0

    Default JdesktopPane

    I have a situation where i would like to have an internal frame inside of a jdesktoppane. Currently that works but i would like to have buttons and labels and other components showing on the jdesktoppane (not related to the internal frame). So far the buttons that i made don't show on the the desktoppane. Please help me figure out why it is not displaying. Here's the code...
    Java Code:
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    
    public class InternalFrame extends JFrame
    {
    	JDesktopPane desktop;
    	private JPanel background;
    
    	public InternalFrame()
    	{
    		super("Internal Frames");
    		this.setExtendedState(Frame.MAXIMIZED_BOTH);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		//this.setLayout(null);
    
    		background = new JPanel();
    		background.setLocation(0,0);
    		background.setLayout(new FlowLayout());
    
    
    	//	setLayout(new FlowLayout());
    
    		JButton button1 = new JButton("Button 1");
    		JButton button2 = new JButton("Button 2");
    		JButton button3 = new JButton("Button 3");
    
    		//button1.setBounds(10,200,200,200);
    
    		background.add(button1);
    		add(button2);
    		add(button3);
    
    		setVisible(true);
    
    		desktop = new JDesktopPane();
    		createFrame();
    		setContentPane(desktop);
    		desktop.add(background);
    	}
    
    
    
    
    	protected void createFrame()
    	{
    		MyInternalFrame frame = new MyInternalFrame();
    		MyInternalFrame frame2 = new MyInternalFrame();
    		frame.setVisible(true);
    		frame2.setVisible(true);
    		desktop.add(frame);
    		desktop.add(frame2);
    	/*	try
    		{
    			frame.setSelected(true);
    		}catch (java.beans.PropertyVetoException e) {} */
    	}
    
    
    		protected void quit()
    		{
    			System.exit(0);
    		}
    
    		private static void createAndShowGUI()
    		{
    			JFrame.setDefaultLookAndFeelDecorated(true);
    
    			InternalFrame frame = new InternalFrame();
    			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    			frame.setVisible(true);
    
    			JFrame.setDefaultLookAndFeelDecorated(true);
    
    			InternalFrame frame2 = new InternalFrame();
    			frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    			frame2.setVisible(true);
    		}
    		public static void main(String[] args)
    		{
    			javax.swing.SwingUtilities.invokeLater(new Runnable()
    			{
    
    			public void run()
    			{
    				createAndShowGUI();
    			}
    		});
    		}
    	}

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,406
    Rep Power
    20

    Default Re: JdesktopPane

    Quote Originally Posted by jumpman8947 View Post
    i would like to have buttons and labels and other components showing on the jdesktoppane (not related to the internal frame).
    Why? Wouldn't it be better to have the buttons/labels in a JPanel displayed alongside/above/below the JDesktopPane?

    JDesktopPane uses a layout manager that allows it to deal with JInternalFrames being moved, iconified, restored and maximized. Short of a major effort entailing creating your own DesktopPaneUI, you're not going to get it to display other components where you want them to be.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Posts
    38
    Rep Power
    0

    Default Re: JdesktopPane

    Yes that's what I'm trying to do with backgroundpanel, add buttons to the panel to display on the screen, and have the internal frame as its separate function.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,406
    Rep Power
    20

    Default Re: JdesktopPane

    Quote Originally Posted by jumpman8947 View Post
    Yes that's what I'm trying to do with backgroundpanel, add buttons to the panel to display on the screen, and have the internal frame as its separate function.
    And what problem are you facing with that?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Posts
    38
    Rep Power
    0

    Default Re: JdesktopPane

    the problem is the buttons are not displaying

  6. #6
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Posts
    38
    Rep Power
    0

    Default Re: JdesktopPane

    Problem solved the buttons wasn't displaying because i wasn't adding the buttons to the desktop. Here's a copy of the working code, (PS, i know the code format is sloppy and may be confusing but i'm currently in the process of figuring out which layout manager i want to use.)
    Java Code:
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    
    public class InternalFrame extends JFrame
    {
    	JDesktopPane desktop;
    	private JPanel background;
    
    	public InternalFrame()
    	{
    		super("Internal Frames");
    		this.setExtendedState(Frame.MAXIMIZED_BOTH);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		//this.setLayout(null);
    
    		//background = new JPanel();
    		//background.setLocation(300,300);
    		//background.setLayout(new FlowLayout());
    
    
    	//	setLayout(new FlowLayout());
    
    		JButton button1 = new JButton("Button 1");
    		JButton button2 = new JButton("Button 2");
    		JButton button3 = new JButton("Button 3");
    
    
    		//background.add(button1);
    		//add(button2);
    		//add(button3);
    
    
    
    		setLayout(null);
    
    		/* JPanel panel1 = new JPanel();
    		JPanel panel2 = new JPanel();
    		JPanel panel3 = new JPanel();
    
    		panel1.add(button1);
    		panel2.add(button2);
    		panel3.add(button3);
    
    		add(panel1, BorderLayout.NORTH);
    		add(panel2, BorderLayout.SOUTH);
    		add(panel3, BorderLayout.CENTER); */
    
    	/*	add(button1, BorderLayout.NORTH);
    		add(button2, BorderLayout.SOUTH);
    		add(button3, BorderLayout.EAST); */
    		pack();
    
    		setVisible(true);
    
    		desktop = new JDesktopPane();
    		createFrame();
    		setContentPane(desktop);
    		//desktop.add(background);
    		desktop.add(button1);
    		desktop.add(button2);
    
    		button1.setBounds(100,100,200,200);
    	}
    
    
    
    
    	protected void createFrame()
    	{
    		MyInternalFrame frame = new MyInternalFrame();
    		MyInternalFrame frame2 = new MyInternalFrame();
    		frame.setVisible(true);
    		frame2.setVisible(true);
    		desktop.add(frame);
    		desktop.add(frame2);
    	/*	try
    		{
    			frame.setSelected(true);
    		}catch (java.beans.PropertyVetoException e) {} */
    	}
    
    
    		protected void quit()
    		{
    			System.exit(0);
    		}
    
    		private static void createAndShowGUI()
    		{
    			JFrame.setDefaultLookAndFeelDecorated(true);
    
    			InternalFrame frame = new InternalFrame();
    			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    			frame.setVisible(true);
    
    			JFrame.setDefaultLookAndFeelDecorated(true);
    
    			InternalFrame frame2 = new InternalFrame();
    			frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    			frame2.setVisible(true);
    		}
    		public static void main(String[] args)
    		{
    			javax.swing.SwingUtilities.invokeLater(new Runnable()
    			{
    
    			public void run()
    			{
    				createAndShowGUI();
    			}
    		});
    		}
    	}

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: JdesktopPane

    The basic code for creating your GUI should be:

    Java Code:
    JPanel south = new JPanel();
    south.add( new JButton("Button1") );
    south.add( new JButton("Button2") );
    
    frame.add(south, BorderLayout.SOUTH);
    
    JDesktopPane desktop = new JDesktopPane();
    frame.add(desktop, BorderLayout.CENTER);
    The desktop and the panel are separate components added to different positions on the frame.
    DarrylBurke likes this.

Similar Threads

  1. JDesktopPane contains JPanel?
    By chyrl in forum Advanced Java
    Replies: 1
    Last Post: 09-22-2010, 12:01 PM
  2. add a panel to jdesktoppane
    By shaay in forum NetBeans
    Replies: 4
    Last Post: 08-08-2010, 04:10 PM
  3. JDesktopPane Design
    By t500yo in forum AWT / Swing
    Replies: 5
    Last Post: 08-03-2010, 03:19 PM
  4. JDesktoppane?
    By skatefreak in forum New To Java
    Replies: 2
    Last Post: 01-31-2009, 05:32 PM
  5. How to add SystemTray to JDesktopPane
    By elisabethkron@yahoo.co.uk in forum Advanced Java
    Replies: 0
    Last Post: 04-07-2008, 08:37 PM

Posting Permissions

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