W
Wes Batson
I have recently begun trying to make a splash screen in which the
background is an image and several labels of information are received
from a database and dynamically placed on top of the image in several
designated spots. I have tried to implement this using a JLayeredPane
inside a JWindow in which the background is added into layer 0 and all
labels added into layer 1. Here is my simplified code.
JWindow container = new JWindow();
JLayeredPane laypane = new JLayeredPane();//creates new label
containing image
laypane.setPreferredSize(new Dimension(container.getWidth(),
container.getHeight()));
JLabel lab = new JLabel(imgi);
laypane.add(lab, new Integer(0));//centers the background inside a
content pane
//Here lies code to receive info from the database. The following
code exists inside a while loop to go through each row and pull out
label text:
JLabel lab2 = new JLabel(resultSet.getString("FRCTLB"));//sets the
label content
lab2.setVerticalAlignment(JLabel.TOP);
lab2.setHorizontalAlignment(JLabel.CENTER);
lab2.setOpaque(true);
lab2.setBounds(resultSet.getInt("FRCTX"),resultSet.getInt("FRCTY"),lab2.getWidth(),lab2.getHeight());
laypane.add(lab2, new Integer(1));
//Then at the end of my function I have these lines of code:
container.getContentPane().add(laypane, BorderLayout.CENTER);
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();//determines screensize
for background
Dimension labelSize = lab.getPreferredSize();//determines the
labelsize for image
container.setLocation(screenSize.width/2 - (labelSize.width/2),
screenSize.height/2 - (labelSize.height/2));//sets the location of
background
container.pack();
container.setVisible(true);//shows the container
My problem is this
When I just add the background label to the JWindow container it shows
up fine, but then I can't get subsequent labels to show up on top of
that label. So I decided to use a JLayeredPane to put the background
label on a different layer than the rest of them. But when I add the
labels to the different layers and it reaches setVisible() nothing
shows up. I'm not sure what the problem is. I am new to java and I
know I have to use a certain layout for the JLayeredPane and was going
to use a GridBagLayout for sophistication reasons.
In sum, I am not sure why the JLayeredPane does not show up when the
pane is added to the container and setVisible is called.
background is an image and several labels of information are received
from a database and dynamically placed on top of the image in several
designated spots. I have tried to implement this using a JLayeredPane
inside a JWindow in which the background is added into layer 0 and all
labels added into layer 1. Here is my simplified code.
JWindow container = new JWindow();
JLayeredPane laypane = new JLayeredPane();//creates new label
containing image
laypane.setPreferredSize(new Dimension(container.getWidth(),
container.getHeight()));
JLabel lab = new JLabel(imgi);
laypane.add(lab, new Integer(0));//centers the background inside a
content pane
//Here lies code to receive info from the database. The following
code exists inside a while loop to go through each row and pull out
label text:
JLabel lab2 = new JLabel(resultSet.getString("FRCTLB"));//sets the
label content
lab2.setVerticalAlignment(JLabel.TOP);
lab2.setHorizontalAlignment(JLabel.CENTER);
lab2.setOpaque(true);
lab2.setBounds(resultSet.getInt("FRCTX"),resultSet.getInt("FRCTY"),lab2.getWidth(),lab2.getHeight());
laypane.add(lab2, new Integer(1));
//Then at the end of my function I have these lines of code:
container.getContentPane().add(laypane, BorderLayout.CENTER);
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();//determines screensize
for background
Dimension labelSize = lab.getPreferredSize();//determines the
labelsize for image
container.setLocation(screenSize.width/2 - (labelSize.width/2),
screenSize.height/2 - (labelSize.height/2));//sets the location of
background
container.pack();
container.setVisible(true);//shows the container
My problem is this
When I just add the background label to the JWindow container it shows
up fine, but then I can't get subsequent labels to show up on top of
that label. So I decided to use a JLayeredPane to put the background
label on a different layer than the rest of them. But when I add the
labels to the different layers and it reaches setVisible() nothing
shows up. I'm not sure what the problem is. I am new to java and I
know I have to use a certain layout for the JLayeredPane and was going
to use a GridBagLayout for sophistication reasons.
In sum, I am not sure why the JLayeredPane does not show up when the
pane is added to the container and setVisible is called.