954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

JAVA GUI Prob: Components only appear when frame edge clicked.

This is really frustrating.
Whenever I run this, a blank window frame appears
The components only appear when I click the edge of the frame.

Please check if I did something wrong:

import javax.swing.*;
import java.awt.*;


/**
 * 
 */


public class FFGen{
	
	
	public void First(){
		
		/**
		 * @param args
		 */
		JLabel pleaseChooseFFType;
		String[] FlipflopTypes = {"JK", "RS", "D", "T"};; 
		JList FlipflopList;
		
		JLabel pleaseChooseFFNum;
		ButtonGroup FlipflopNumberGroup;
		JRadioButtonMenuItem oneFlipflop;
		JRadioButtonMenuItem twoFlipflop;
		
		JLabel pleaseCheck;
		JCheckBox oneInput;
		JCheckBox oneOutput;
		
		JButton next;
		
		JFrame first;
		JPanel firstConLeft;
		JPanel firstConRight;
	
		FlipflopList = new JList(FlipflopTypes);
		FlipflopList.setVisibleRowCount(1);
		JScrollPane scroller = new JScrollPane(FlipflopList);
		
		pleaseChooseFFType = new JLabel("Type of Flipflop:");
		oneFlipflop = new JRadioButtonMenuItem ("1");
		twoFlipflop = new JRadioButtonMenuItem ("2");
		
		pleaseChooseFFNum = new JLabel("Number of Flipflops:");
		FlipflopNumberGroup = new ButtonGroup();
		FlipflopNumberGroup.add(oneFlipflop);
		FlipflopNumberGroup.add(twoFlipflop);
		
		pleaseCheck = new JLabel("There is an:");
		oneInput = new JCheckBox ("Input");
		oneOutput = new JCheckBox ("Output");
		
		next = new JButton ("Next");
		
		first =  new JFrame();
		first.setSize(250,235);
		first.setVisible(true);
		
		firstConLeft = new JPanel();
		firstConRight = new JPanel();
		firstConRight.setLayout(new GridLayout(9,1,0,0));
		firstConRight.add(pleaseChooseFFType);
		firstConRight.add(scroller);
		firstConRight.add(pleaseChooseFFNum);
		firstConRight.add(oneFlipflop);
		firstConRight.add(twoFlipflop);
		firstConRight.add(pleaseCheck);
		firstConRight.add(oneInput);
		firstConRight.add(oneOutput);
		firstConRight.add(next);
		
		JPanel Empty = new JPanel();
		Empty.setLayout(new GridLayout(1,2));
		Empty.add(firstConLeft);
		Empty.add(firstConRight);
		first.add(Empty);
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FFGen gui = new FFGen();
		gui.First();
	}

}

Thank you.

einjelle
Newbie Poster
9 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

It shows up correctly for me without having to click anything. Often, if you need to click, move, resize, or maximize/minimize something for it to show up, you can solve it by using the validate () from the Container class.

http://java.sun.com/javase/6/docs/api/java/awt/Container.html#validate( )

But again, I did not have to do this. I was able to see your GUI without doing anything.

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

It shows up correctly for me without having to click anything. Often, if you need to click, move, resize, or maximize/minimize something for it to show up, you can solve it by using the validate () from the Container class.

http://java.sun.com/javase/6/docs/api/java/awt/Container.html#validate( )

But again, I did not have to do this. I was able to see your GUI without doing anything.

I know.. It's weird..
Thanks.. I'll try that now.

einjelle
Newbie Poster
9 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Based on the swing Sun example:

public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                //FFGen gui = new FFGen(); 
                new FFGen();
            }
        });
    }

Write constructor for FFGen:

public FFGen() {
        First();
    }

Under Windows XP I have no problem. Same as VernonDozier.
What is your Operating System?

quuba
Posting Pro
573 posts since Nov 2008
Reputation Points: 123
Solved Threads: 106
 

based on the swing sun example:

public static void main(string[] args) {
        //schedule a job for the event-dispatching thread:
        //creating and showing this application's gui.
        Javax.swing.swingutilities.invokelater(new runnable() {

            public void run() {
                //ffgen gui = new ffgen(); 
                new ffgen();
            }
        });
    }

write constructor for ffgen:

public ffgen() {
        first();
    }

under windows xp i have no problem. Same as vernondozier. What is your operating system?

i am also using xp.
I really can't understand why that happens.i've done other gui interfaces before and they run just fine.
But i just can't figure this one out.

I asked a friend of mine to run it in his computer, and he gets the same result as mine.

einjelle
Newbie Poster
9 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Did adding validate () not do anything?

Try moving lines 57 and 58 from where they are to the BOTTOM of the function. Then add:

first.validate ();


at the very bottom of the function. See if that makes a difference. I'm not sure it will, but it's worth a shot.

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

Did adding validate () not do anything?

Try moving lines 57 and 58 from where they are to the BOTTOM of the function. Then add:

first.validate ();

at the very bottom of the function. See if that makes a difference. I'm not sure it will, but it's worth a shot.


0__0 Thanks. It worked!
Thank you.. >(~__~)

einjelle
Newbie Poster
9 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: