wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Images in a LayerPane wont show up. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Images in a LayerPane wont show up." Watch "Images in a LayerPane wont show up." New topic
Author

Images in a LayerPane wont show up.

pet lia
Greenhorn

Joined: Nov 17, 2005
Posts: 1
I have three images that I want to show layered, one being a background, and the other two being text in front of the background. But when I executed it, nothing shows up. Then I test it by just adding the images without LayerPane, and they all showed up. What's the problem?

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.lang.reflect.*;



public class Menu extends JFrame implements ActionListener
{
static int width = 570, height = 770;

String name;


JLabel startImageLabel;
JLabel csTitleLabel;
JLabel rpgLabel;

JButton startGame;
JButton options;
JButton credits;
JButton quit;

JPanel startGamePanel;
JPanel optionsPanel;
JPanel creditsPanel;
JPanel quitPanel;

JPanel titlePanel;
JPanel menuPanel;
JPanel titleFinalPanel;


ImageIcon startBackground;
ImageIcon csTitle;
ImageIcon rpgTitle;

Box menuBox;
Box startBox;
Box titleBox;

JLayeredPane titleLayer;



public Menu()
{

setTitle("Counter Strike RPG");


csTitle = new ImageIcon("cs.gif");
rpgTitle = new ImageIcon("rpg.gif");
startBackground = new ImageIcon("cs6.jpg");

csTitleLabel = new JLabel(csTitle, JLabel.CENTER);
csTitleLabel.setOpaque(true);

rpgLabel = new JLabel(rpgTitle, JLabel.CENTER);
rpgLabel.setOpaque(true);

startImageLabel = new JLabel(startBackground, JLabel.CENTER);
startImageLabel.setOpaque(true);


titleLayer = new JLayeredPane();
titleLayer.setPreferredSize( new Dimension(550, 350) );
titleLayer.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
Point origion = new Point(0,0);
titleLayer.add(startImageLabel, new Integer(0));
titleLayer.add(csTitleLabel, new Integer(1));
titleLayer.add(rpgLabel, new Integer(2));



startGame = new JButton(" StartGame ");
options = new JButton(" Options ");
credits = new JButton(" Credits ");
quit = new JButton(" Quit ");

startGamePanel = new JPanel(); startGamePanel.add(startGame);
optionsPanel = new JPanel(); optionsPanel.add(options);
creditsPanel = new JPanel(); creditsPanel.add(credits);
quitPanel = new JPanel(); quitPanel.add(quit);

startGamePanel.setBorder(BorderFactory.createRaisedBevelBorder());
optionsPanel.setBorder(BorderFactory.createRaisedBevelBorder());
creditsPanel.setBorder(BorderFactory.createRaisedBevelBorder());
quitPanel.setBorder(BorderFactory.createRaisedBevelBorder());



menuPanel = new JPanel();
menuPanel.setLayout(
new BoxLayout( menuPanel, BoxLayout.Y_AXIS ) );
menuPanel.add(startGamePanel);
menuPanel.add(optionsPanel);
menuPanel.add(creditsPanel);
menuPanel.add(quitPanel);





menuBox = new Box( BoxLayout.X_AXIS );
menuBox.add( Box.createHorizontalGlue() );
menuBox.add( menuPanel );
menuBox.add( Box.createHorizontalGlue() );

startBox = new Box( BoxLayout.Y_AXIS );
startBox.add(titleLayer);
startBox.add(Box.createVerticalGlue() );
startBox.add(menuBox);
startBox.add(Box.createVerticalGlue() );


getContentPane().add(startBox);

startGame.setActionCommand("start");
options.setActionCommand("options");
credits.setActionCommand("credits");
quit.setActionCommand("quit");

startGame.addActionListener( this );
options.addActionListener( this );
credits.addActionListener( this );
quit.addActionListener( this );

Toolkit tk = Toolkit.getDefaultToolkit();
Dimension screenSize = tk.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
setLocation(screenWidth / 4, 0);



}

public void actionPerformed(ActionEvent evt)
{
String getCommand;


if(evt.getSource().equals(startGame))
{
do
{
name = JOptionPane.showInputDialog("Enter Username");
}while(name.length()<1);

Teamselect ts = new Teamselect();
ts.setSize(570,770);
ts.setVisible(true);

}
repaint();

}





public static void main(String[] args)
{

Menu menu = new Menu();
menu.setSize(width, height);
menu.setVisible(true);



WindowQuitter wq = new WindowQuitter();
menu.addWindowListener(wq);


try
{

Thread.sleep(0000);
Runnable printImage = new Runnable()
{
public void run()
{

}
};

SwingUtilities.invokeAndWait(printImage);
}

catch(InterruptedException ix)
{
}
catch(InvocationTargetException x)
{
}

}

}

class WindowQuitter extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Images in a LayerPane wont show up.