Posted on 2005-03-18
Medium Priority
Last Modified: 2012-05-05
Hi guys,

I know it is possible to add JInternalFrames to a JDesktop, however is it possible to add panels to a JDesktop? and then work on the panels to give a templat that is alway there?

Kind regards

Question by:peterwittering
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Expert Comment

ID: 13573432
You need a specific background - say an image? I'm getting a sense of deja vu here - was it you? ;-)

Author Comment

ID: 13573474
was what me?

Author Comment

ID: 13573502
what i intend to do is have two panels one with the login controls on left hand side, and one with the application language selection controls on the right about a 25-75% horizontally.  These need to be visible until a correct username and password is provided.  Upon that the two panel will disappear and open the relevant JInternalFrames relevant to the users rights.  Also a image icon covering the JDesktop background.  I know i could add the two panels to a JInternalframe, however would like them to be there all the time so that the user could not minimise or remove it.
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

LVL 35

Expert Comment

ID: 13573506
JDesktop is a Container, so yes it should be possible

Or of course, you should be able to just use a JInternalFrame that is not closable, iconifiable, or maximisable :-)
LVL 35

Expert Comment

ID: 13573524
>> however would like them to be there all the time so that the user could not minimise or remove it.

Ahhh...why not use the GlassPane of your application?

LVL 35

Accepted Solution

TimYates earned 2000 total points
ID: 13573642
Kind of like this (this is a poor example, but you should see what I mean...)


import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;

public class LoginTest extends JFrame
  class MyGlassPane extends JPanel
    JPanel loginPanel = new JPanel( new FlowLayout() ) ;
    JButton login = new JButton( "Login!" ) ;
    JTextArea username = new JTextArea() ;
    public MyGlassPane()
      setOpaque( false ) ;
      setLayout( new GridBagLayout() ) ;
      loginPanel.add( new JLabel( "Username" ) ) ;
      loginPanel.add( username ) ;
      loginPanel.add( login ) ;
      add( loginPanel ) ;
      login.addActionListener( new ActionListener()
        public void actionPerformed( ActionEvent e )
          // pretend we have logged in successfully!
          glass.setVisible( false ) ;
      } ) ;

    public void paintComponent( Graphics g )
      super.paintComponent( g ) ;
      g.setColor( new Color( 0, 0, 0, 64 ) ) ;
      g.fillRect( 0, 0, this.getWidth(), this.getHeight() ) ;

  MyGlassPane glass = new MyGlassPane() ;
  JDesktopPane desktop = new JDesktopPane() ;

  public LoginTest( String title )
    super( title ) ;
    getContentPane().setLayout( new BorderLayout() ) ;
    getContentPane().add( desktop, BorderLayout.CENTER ) ;
    getContentPane().add( new JLabel( "Another component" ), BorderLayout.NORTH ) ;
    getContentPane().add( new JLabel( "West!" ), BorderLayout.WEST ) ;

    setSize( 800, 600 ) ;
    setGlassPane( glass ) ;
    glass.setVisible( true ) ;

  public static void main( String[] args ) throws HeadlessException
    LoginTest loginTest1 = new LoginTest( "LoginTest" ) ;
    loginTest1.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ) ;
    loginTest1.setLocationRelativeTo( null ) ;
    loginTest1.setVisible( true ) ;

Expert Comment

ID: 13573719
u need to add JSplit panes for this purpose.

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question