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

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 9
Reputation: einjelle is an unknown quantity at this point 
Solved Threads: 0
einjelle's Avatar
einjelle einjelle is offline Offline
Newbie Poster

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

 
0
  #1
Sep 20th, 2009
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,833
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

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

 
0
  #2
Sep 20th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: einjelle is an unknown quantity at this point 
Solved Threads: 0
einjelle's Avatar
einjelle einjelle is offline Offline
Newbie Poster

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

 
0
  #3
Sep 21st, 2009
Originally Posted by VernonDozier View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 54
quuba quuba is offline Offline
Posting Whiz

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

 
0
  #4
Sep 21st, 2009
Based on the swing Sun example:
  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:
  1. public FFGen() {
  2. First();
  3. }
Under Windows XP I have no problem. Same as VernonDozier.
What is your Operating System?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: einjelle is an unknown quantity at this point 
Solved Threads: 0
einjelle's Avatar
einjelle einjelle is offline Offline
Newbie Poster

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

 
0
  #5
Sep 22nd, 2009
Originally Posted by quuba View Post
based on the swing sun example:
  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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,833
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

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

 
0
  #6
Sep 22nd, 2009
Did adding validate () not do anything?

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

  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: einjelle is an unknown quantity at this point 
Solved Threads: 0
einjelle's Avatar
einjelle einjelle is offline Offline
Newbie Poster

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

 
0
  #7
Sep 22nd, 2009
Originally Posted by VernonDozier View Post
Did adding validate () not do anything?

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

  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.. >(~__~)<
Reply With Quote Quick reply to this message  
Reply

Tags
gui, java

Message:


Thread Tools Search this Thread



Tag cloud for gui, java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC