Java swing application problem

Status
Not open for further replies.

glenthas

Ars Tribunus Angusticlavius
6,979
Subscriptor++
So I'm trying to code a swing application, but regardless of what I try I can't seem to get it to work. Despite any background chnages, or components added all I see is a big grey JFrame. When it's first created I'll see my chosen background color flash by before it becomes a featurelss grey frame.

For testing I've created this fairly simple app.
Code:
import javax.swing.*;
import java.awt.*;

public class testJFrame
{
	public static JFrame myJFrame = new JFrame("Test JFrame");
	
	public static void main(String[] args)
	{
		myJFrame.setSize(500,200);
		myJFrame.setBackground(Color.red);
		myJFrame.setVisible(true);
	}
}

Am I just making some obvious mistake or does this work for everyone else? For the record I'm using visual J++ on winXP Pro. I've also tried it in forte 3.0.

Thanks for your help

Brian
 

glenthas

Ars Tribunus Angusticlavius
6,979
Subscriptor++
Okay, that's working fine, however I've run into another problem I can't quite figure out.

Code:
public Component createPlayingField()
	{
		
		//ImageIcon buttonImage = new ImageIcon("images/card.gif");
		pane = new JPanel();
		pane.setLayout(new BorderLayout());
		pane.setBackground(Color.red);
		JPanel centerPane = new JPanel();
		centerPane.setBackground(Color.red);
		centerPane.setLayout(new BoxLayout(centerPane, BoxLayout.Y_AXIS));
		button = new JButton("Blah");
		centerPane.add(button);
		button2 = new JButton();
		centerPane.add(button2);
		createMenus();
		pane.add(centerPane, BorderLayout.CENTER);
		return pane;
	}

The above works fine until I uncomment the ImageIcon line. At that point I'm back to a grey panel. Probably something obvious I'm missing this time as well...Any ideas?

Thanks,

Brian
 
Status
Not open for further replies.