Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages
Started by Ishan
Sat, 07 Feb 2004 20:42
JLayeredPanes are not showing up!
Author: Ishan
Date: Sat, 07 Feb 2004 20:42
Date: Sat, 07 Feb 2004 20:42
63 lines
2703 bytes
2703 bytes
I can't get his code to work.
The layers will not display. Please help. It's on XP, using JBuilder 9.
package testinglayers;
import javax.swing.*;
import java.awt.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class layerDemo {
public layerDemo() {
JFrame jf = new JFrame("Layered Demo");
JLabel lb = new JLabel("Testing");
JLabel lb2 = new JLabel("Testing 2");
JLayeredPane lp = new JLayeredPane();
JLayeredPane lp2 = jf.getLayeredPane();
lp2.setSize(new Dimension(200,200));
jf.setBackground(Color.WHITE);
lp2.enable();
lp2.doLayout();
lp2.setSize(new Dimension(400,400));
lp2.add(lb, JLayeredPane.DEFAULT_LAYER);
lp2.add(lb2, JLayeredPane.PALETTE_LAYER);
lp2.setBackground(Color.PINK);
lp2.show();
// lp2.show(true);
lp2.validate();
lp2.grabFocus();
jf.setSize(new Dimension(500,500));
// lp2.setEnabled(true);
lp2.setForeground(Color.BLUE);
System.out.println("Size of Layer: " +lp2.getSize());
System.out.println("Is Enable: " + lp2.isEnabled());
System.out.println("Is Showing: " + lp2.isShowing());
lp2.setVisible(true);
System.out.println("Is Visable: " + lp2.isVisible());
System.out.println("Is Displayable: " + lp2.isDisplayable());
System.out.println("Is DoubleBuffered: " + lp2.isDoubleBuffered());
// jf.getContentPane().setBackground(Color.WHITE);
jf.setLayeredPane(lp2);
jf.show();
// System.out.println("This is the total number of components: " + lp2.countComponents());
}
public static void main(String[] args) {
layerDemo layerDemo1 = new layerDemo();
}
}
This is driving me crazy!!!!!
Re: JLayeredPanes are not showing up!
Author: John McGrath [TeamB]
Date: Thu, 12 Feb 2004 15:37
Date: Thu, 12 Feb 2004 15:37
28 lines
1751 bytes
1751 bytes
On 2/7/2004 at 3:42:28 PM, Ishan wrote:
> I can't get his code to work.
> The layers will not display.
The reason that the layered pane does not display anything is that it
is not supposed to. It is simply a container for holding other
components.
The reason that the labels do not display is because nothing has set
their sizes, so they all have a size of [0,0]. The layered pane does
not manage the bounds for the components that it contains, so you have
to provide the code to do that.
If you add the following code, you will see the labels.
lb.setSize( lb.getPreferredSize() );
lb2.setSize( lb2.getPreferredSize() );
lb2.setLocation( 0, 20 );
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads