Jump to content

Is this a windows Vista issue?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
nolsen01

nolsen01

    Newbie

  • Members
  • Pip
  • 5 posts
I'm currently in class for Data Structures and Algorithms and we are having a little problem our code.

We are using Turbo JBuilder from Borland, it uses the Eclipse IDE.

The following code doesn't show the label or buttons until you try and resize the window. Does anyone have any idea why?


import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;



public class SimpleApp extends JFrame implements ActionListener

{

	JLabel lbl = new JLabel("Hello World");

	JButton btn1 = new JButton("Red");

	JButton btn2 = new JButton("Green");

	

	Container content = this.getContentPane();

	

	

	public SimpleApp()

	{

		

		

		this.setDefaultCloseOperation(EXIT_ON_CLOSE);

		this.setLayout(new FlowLayout());

		content.add(lbl);

		content.add(btn1);

		btn1.addActionListener(this);

		content.add(btn2);

		btn2.addActionListener(this);

		this.setVisible(true);

		this.setSize(300,200);

		

	}

	

	

	

	public static void main(String[] args) 

	{

		

		new SimpleApp();

		

				

	}




	public void actionPerformed(ActionEvent e)

	{

		

		JButton b = (JButton) e.getSource();

		

		if(b == btn1)

			lbl.setForeground(Color.RED);

		else

			lbl.setForeground(Color.GREEN);

		

		

	}

	

	


}


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
No that is not a Vista issue. Try to pack() your window.

#3
nolsen01

nolsen01

    Newbie

  • Members
  • Pip
  • 5 posts
pack() did indeed work.

I did not know about that method. its pretty useful. I'm also wondering if resize() would work? eh, I'm not going to worry about it.

Thanks by the way.

#4
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
No problem. If I recall, when I was taking Java classes, and was developing in Linux I did not need to pack my window, and then when I started developing in Windows I ran into the same problem. But I'm still not sure if I would call it a Windows issue, as packing your window is the proper way to code.