Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2005

Tip: Looking for answers? Try searching our database.

JLayeredPane possible in BorderLayout.CENTER ?

Thread view: 
alex_us01 - 30 Sep 2005 18:32 GMT
hi,
I tried to use JLayeredPane as follows and nothing in it shows up.
What is the problem?

thanks,
alex

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

public class LPTry {

    public static void main(String[] args) {
        JFrame jf = new JFrame();
        jf.getContentPane().setLayout(new BorderLayout());

        JLabel tlabel = new JLabel("east");

        jf.getContentPane().add(tlabel, BorderLayout.EAST);

        JLayeredPane lpane = new JLayeredPane();
        tlabel = new JLabel("center bottom");
        lpane.add(tlabel, JLayeredPane.DEFAULT_LAYER);

        jf.getContentPane().add(lpane, BorderLayout.CENTER);
       
        jf.pack();
        jf.setVisible(true);
       
    }
}
alex_us01 - 30 Sep 2005 19:01 GMT
as far as i understand, that is because there is no layout manager is
set for the JLayeredPane.

Solution:
either: lpane.setLayoutManager( /* some manager */ );

or:  tlabel.setBounds(0,0,100,10);

and here is the code that shows overlapping components:
============================================

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

public class LPTry {

    public static void main(String[] args) {
        JFrame jf = new JFrame();
        jf.getContentPane().setLayout(new BorderLayout());

        JLabel tlabel = new JLabel("east");

        jf.getContentPane().add(tlabel, BorderLayout.EAST);

        JLayeredPane lpane = new JLayeredPane();
        tlabel = new JLabel("center bottom");
        tlabel.setBounds(0,0,100,10);
        lpane.setPreferredSize(new Dimension(200,100));
        lpane.add(tlabel, JLayeredPane.DEFAULT_LAYER);
        tlabel = new JLabel("center top");
        tlabel.setBounds(0,0,100,10);
        tlabel.setForeground(Color.RED);
        tlabel.setOpaque(false);
        lpane.add(tlabel, JLayeredPane.PALETTE_LAYER);

        jf.getContentPane().add(lpane, BorderLayout.CENTER);
       
        jf.pack();
        jf.setVisible(true);
       
    }
}
Vova Reznik - 30 Sep 2005 19:21 GMT
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class LPTry {

    public static void main(String[] args) {
        JFrame jf = new JFrame();

        JLabel lblN = new JLabel("North", JLabel.CENTER);
        JLabel lblC = new JLabel("Center", JLabel.CENTER);
        JLabel lblS = new JLabel("South", JLabel.CENTER);

        JPanel lblPanel = new JPanel(null);

        Dimension size = new Dimension(50, 60);
        lblPanel.setSize(size);
        lblPanel.setPreferredSize(size);
        lblPanel.add(lblN);
        lblPanel.add(lblC);
        lblPanel.add(lblS);

        lblN.setBounds(0, 0, 40, 15);
        lblC.setBounds(0, 20, 40, 15);
        lblS.setBounds(0, 40, 40, 15);

        JPanel pnlGlass = new JPanel();
        pnlGlass.setOpaque(false);
        pnlGlass.setSize(size);
        pnlGlass.setPreferredSize(size);
        pnlGlass.setLocation(0, 0);
        pnlGlass.add(new JLabel("-_-_-_"));

        lblPanel.add(pnlGlass);

        jf.getContentPane().add(lblPanel);

        jf.pack();
        jf.setVisible(true);

    }
}
Roedy Green - 30 Sep 2005 21:16 GMT
>jf.pack();

This squeezes everything to its minimum size.  See
http://mindprod.com/jgloss/pack.html

You might want to use validate instead
http://mindprod.com/jgloss/validate.html

and give your JLayeredPane a size, minimumSize, PreferredSize and
MaximumSize.  JLayeredPanes don't seem to have a proper layout
manager, so I gather you must treat them as if it were null.

http://mindprod.com/jgloss/layout.html

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.