943,816 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1542
  • Java RSS
Sep 20th, 2009
0

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

Expand Post »
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:

Java Syntax (Toggle Plain Text)
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4.  
  5. /**
  6.  *
  7.  */
  8.  
  9.  
  10. public class FFGen{
  11.  
  12.  
  13. public void First(){
  14.  
  15. /**
  16. * @param args
  17. */
  18. JLabel pleaseChooseFFType;
  19. String[] FlipflopTypes = {"JK", "RS", "D", "T"};;
  20. JList FlipflopList;
  21.  
  22. JLabel pleaseChooseFFNum;
  23. ButtonGroup FlipflopNumberGroup;
  24. JRadioButtonMenuItem oneFlipflop;
  25. JRadioButtonMenuItem twoFlipflop;
  26.  
  27. JLabel pleaseCheck;
  28. JCheckBox oneInput;
  29. JCheckBox oneOutput;
  30.  
  31. JButton next;
  32.  
  33. JFrame first;
  34. JPanel firstConLeft;
  35. JPanel firstConRight;
  36.  
  37. FlipflopList = new JList(FlipflopTypes);
  38. FlipflopList.setVisibleRowCount(1);
  39. JScrollPane scroller = new JScrollPane(FlipflopList);
  40.  
  41. pleaseChooseFFType = new JLabel("Type of Flipflop:");
  42. oneFlipflop = new JRadioButtonMenuItem ("1");
  43. twoFlipflop = new JRadioButtonMenuItem ("2");
  44.  
  45. pleaseChooseFFNum = new JLabel("Number of Flipflops:");
  46. FlipflopNumberGroup = new ButtonGroup();
  47. FlipflopNumberGroup.add(oneFlipflop);
  48. FlipflopNumberGroup.add(twoFlipflop);
  49.  
  50. pleaseCheck = new JLabel("There is an:");
  51. oneInput = new JCheckBox ("Input");
  52. oneOutput = new JCheckBox ("Output");
  53.  
  54. next = new JButton ("Next");
  55.  
  56. first = new JFrame();
  57. first.setSize(250,235);
  58. first.setVisible(true);
  59.  
  60. firstConLeft = new JPanel();
  61. firstConRight = new JPanel();
  62. firstConRight.setLayout(new GridLayout(9,1,0,0));
  63. firstConRight.add(pleaseChooseFFType);
  64. firstConRight.add(scroller);
  65. firstConRight.add(pleaseChooseFFNum);
  66. firstConRight.add(oneFlipflop);
  67. firstConRight.add(twoFlipflop);
  68. firstConRight.add(pleaseCheck);
  69. firstConRight.add(oneInput);
  70. firstConRight.add(oneOutput);
  71. firstConRight.add(next);
  72.  
  73. JPanel Empty = new JPanel();
  74. Empty.setLayout(new GridLayout(1,2));
  75. Empty.add(firstConLeft);
  76. Empty.add(firstConRight);
  77. first.add(Empty);
  78. }
  79.  
  80. public static void main(String[] args) {
  81. // TODO Auto-generated method stub
  82. FFGen gui = new FFGen();
  83. gui.First();
  84. }
  85.  
  86. }


Thank you.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
einjelle is offline Offline
9 posts
since Jun 2009
Sep 20th, 2009
0

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

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/ap...html#validate()

But again, I did not have to do this. I was able to see your GUI without doing anything.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,374 posts
since Jan 2008
Sep 21st, 2009
0

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

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/ap...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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
einjelle is offline Offline
9 posts
since Jun 2009
Sep 21st, 2009
0

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

Based on the swing Sun example:
java Syntax (Toggle Plain Text)
  1. public static void main(String[] args) {
  2. //Schedule a job for the event-dispatching thread:
  3. //creating and showing this application's GUI.
  4. javax.swing.SwingUtilities.invokeLater(new Runnable() {
  5.  
  6. public void run() {
  7. //FFGen gui = new FFGen();
  8. new FFGen();
  9. }
  10. });
  11. }
Write constructor for FFGen:
java Syntax (Toggle Plain Text)
  1. public FFGen() {
  2. First();
  3. }
Under Windows XP I have no problem. Same as VernonDozier.
What is your Operating System?
Reputation Points: 123
Solved Threads: 106
Posting Pro
quuba is offline Offline
573 posts
since Nov 2008
Sep 22nd, 2009
0

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

Click to Expand / Collapse  Quote originally posted by quuba ...
based on the swing sun example:
java Syntax (Toggle Plain Text)
  1. public static void main(string[] args) {
  2. //schedule a job for the event-dispatching thread:
  3. //creating and showing this application's gui.
  4. Javax.swing.swingutilities.invokelater(new runnable() {
  5.  
  6. public void run() {
  7. //ffgen gui = new ffgen();
  8. new ffgen();
  9. }
  10. });
  11. }
write constructor for ffgen:
java Syntax (Toggle Plain Text)
  1. public ffgen() {
  2. first();
  3. }
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
einjelle is offline Offline
9 posts
since Jun 2009
Sep 22nd, 2009
0

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

Did adding validate () not do anything?

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

Java Syntax (Toggle Plain Text)
  1. 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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,374 posts
since Jan 2008
Sep 22nd, 2009
0

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

Did adding validate () not do anything?

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

Java Syntax (Toggle Plain Text)
  1. 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.. >(~__~)<
Reputation Points: 10
Solved Threads: 0
Newbie Poster
einjelle is offline Offline
9 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: AODV routing algorithm
Next Thread in Java Forum Timeline: insert coding in java





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC