Results 1 to 14 of 14
  1. #1
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Exclamation Can JDesktopPane can have a background JPanel?

    Greetings,

    Is this possble? Having a JPanel as background of a JDesktopPane?

    Thanks,
    Cyril H.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

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

    Default

    Why / what for?

    db

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    And why is this question posted in the 'Advanced Java' section?

    kind regards,

    Jos

  4. #4
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Exclamation

    Quote Originally Posted by JosAH View Post
    And why is this question posted in the 'Advanced Java' section?

    kind regards,

    Jos
    This is posted here for a reason, I can't say if it suits the AWT/Swing section.

    Quote Originally Posted by Darryl.Burke View Post
    Why / what for?

    db
    To be specifiy, I was hoping to create a game using this way.
    Setting a JPanel as the background to the JDesktopPane for me to add movable JInternalFrame. To be specific, I want to create an movable internal frames like most MMORPG nowadays.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

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

    Default

    Quote Originally Posted by chyrl View Post
    This is posted here for a reason, I can't say if it suits the AWT/Swing section.
    What about this question does not relate to Swing?
    Seriously. Moving thread.

    To be specifiy, I was hoping to create a game using this way.
    Setting a JPanel as the background to the JDesktopPane for me to add movable JInternalFrame. To be specific, I want to create an movable internal frames like most MMORPG nowadays.
    You still haven't mentioned anything that requires a JPanel as everything mentioned so far requires only the JDesktopPane and however many JInternalFrames needed.

  6. #6
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    I'm not sure about the number of JInternalFrame needed.
    Only the JDesktopPane requires a JPanel, but only that the JPanel must be the background of the JDesktopPane. So when I add a new JInternalFrame to that JDesktopPane, the JPanel will display only in a layered view against the JIFs.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

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

    Default

    Quote Originally Posted by chyrl View Post
    I'm not sure about the number of JInternalFrame needed.
    Only the JDesktopPane requires a JPanel, but only that the JPanel must be the background of the JDesktopPane. So when I add a new JInternalFrame to that JDesktopPane, the JPanel will display only in a layered view against the JIFs.
    Your problem is still not clear. Why do you need a JPanel in the background? Why not just draw in the JDesktopPane's background?

  8. #8
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    I would need a JPanel in the background for in the JPanel,
    JButton, JLabel, JTextField, and more swing components are added on it.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Bad idea, even if implemented. I'd hate to have to use a GUI where internal frames could obscure other interactive elements.

    db

  10. #10
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    I'm not getting a feel for what you're trying to do and am going to ask you to clarify things. Are you creating a JPanel that holds a JDesktopPane, possibly in the BorderLayout.CENTER position, and then going to have JButtons, JTextFields and/or other components in other locations of the JPanel, or are you trying to have the all of these components in a panel in the background of a JDesktopPane? If the latter, then I agree with Darryl, that this doesn't sound like a good user interface design. If the former, then perhaps you should describe in greater detail, complete with images what you're trying to do.

  11. #11
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Actually, what places in the BorderLayout.CENTER is the JDesktopPane,
    and in the JDesktopPane is the JPanel that holds the JButton, JTextField, etc.

    I wanted this so that I could use the JInternalFrame to be my internal frames - frames that is in the JFrame only (does not go beyond the frame).

    If your a Ragnarok Online gamer, the JPanel is where your character moves, and JDesktopPane is where the JPanel. The JInternalFrame is the interface of the Inventory, Skills, Storage, NPC Dialog, etc.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

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

    Default

    If you absolutely have to have a JPanel on the bottom, it can be done with ease -- remember that JDesktopPane extends from a JLayeredPane, and as with any JLayeredPane, you can add components to whichever layer you choose including the bottom or JLayeredPane.DEFAULT_LAYER. e.g.,

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    
    import javax.swing.*;
    
    public class DesktopFoo extends JPanel {
       private static final Dimension DESKTOP_SIZE = new Dimension(800, 600);
       private static final int COLS = 5;
       private static final int ROWS = 6;
       private static final int JIF_MAX = 4;
       private static final Dimension INTERNAL_FRAME_SIZE = new Dimension(300, 200);
       private JDesktopPane desktop = new JDesktopPane();
       private JPanel backgroundPanel = new JPanel();
       
       public DesktopFoo() {
          backgroundPanel.setSize(DESKTOP_SIZE);
          backgroundPanel.setLocation(0, 0);
          backgroundPanel.setBackground(Color.pink);
          int gap = 20;
          backgroundPanel.setLayout(new GridLayout(ROWS, COLS, gap, gap));
          backgroundPanel.setBorder(BorderFactory.createEmptyBorder(gap, gap, gap, gap));
          for (int i = 0; i < ROWS; i++) {
             for (int j = 0; j < COLS; j++) {
                String text = "[" + j + ", " + i + "]";
                JButton btn = new JButton(text);
                backgroundPanel.add(btn);
             }
          }
          
          for (int i = 0; i < JIF_MAX; i++) {
             JInternalFrame internalFrame = new JInternalFrame("Internal Frame " + i);
             internalFrame.setPreferredSize(INTERNAL_FRAME_SIZE);
             internalFrame.pack();
             int offset = 60;
             internalFrame.setLocation(offset + offset * i, offset + offset * i);
             desktop.add(internalFrame);
             internalFrame.setVisible(true);         
          }
          
          desktop.setPreferredSize(DESKTOP_SIZE);
          desktop.add(backgroundPanel, JLayeredPane.DEFAULT_LAYER);
          
          setLayout(new BorderLayout());
          add(desktop, BorderLayout.CENTER);
       }
    
       private static void createAndShowUI() {
          JFrame frame = new JFrame("DesktopFoo");
          frame.getContentPane().add(new DesktopFoo());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }

  13. #13
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Maybe this code will help me out.
    Thanks Fubarable.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

  14. #14
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Quote Originally Posted by chyrl View Post
    Actually, what places in the BorderLayout.CENTER is the JDesktopPane,
    and in the JDesktopPane is the JPanel that holds the JButton, JTextField, etc.

    I wanted this so that I could use the JInternalFrame to be my internal frames - frames that is in the JFrame only (does not go beyond the frame).

    If your a Ragnarok Online gamer, the JPanel is where your character moves, and JDesktopPane is where the JPanel. The JInternalFrame is the interface of the Inventory, Skills, Storage, NPC Dialog, etc.
    Sounds more like undocked toolbars to me.

    db

Similar Threads

  1. JDesktopPane contains JPanel?
    By chyrl in forum Advanced Java
    Replies: 1
    Last Post: 09-22-2010, 01:01 PM
  2. Change JPanel background after its been set once
    By mevets in forum AWT / Swing
    Replies: 4
    Last Post: 04-14-2010, 02:07 AM
  3. background color with jpanel
    By hannerz06 in forum New To Java
    Replies: 6
    Last Post: 03-31-2010, 04:25 AM
  4. how to put a background image in a JPanel
    By yanipao in forum New To Java
    Replies: 5
    Last Post: 10-21-2009, 03:27 PM
  5. Loading an image into JDesktopPane as background
    By Rose88 in forum Advanced Java
    Replies: 13
    Last Post: 08-25-2009, 02:10 AM

Posting Permissions

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