File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Blank Frame or Panel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Blank Frame or Panel" Watch "Blank Frame or Panel" New topic
Author

Blank Frame or Panel

Adam Burda
Ranch Hand

Joined: Jul 19, 2011
Posts: 40
I am running windows 7 64bit Home Premium with an intel core i3 and 4GB of ram. I run my java code in eather prompt or i use JCreator LE. Every time i wright an app I get a blank frame or a blank panel. But only when I put in a JTextArea or a JTextField. Buttons, CheckBoxes, and Raido Buttons all show fine. But when i add a textfield the program compiles fine then i run it. The window pop's up, but nothing on it. Unless i grab one of the sides to adjust the size of the window myself, bigger or smaller. Then the window displays the buttons, textfield...... I have tryed resizing, and using other layouts. I have no clue what the bug is. This happens with any and all code I wright.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

In that case you might want to start with the tutorial about text fields and look at the examples given there.

How to Use Text Fields
Adam Burda
Ranch Hand

Joined: Jul 19, 2011
Posts: 40
Ok I have read the link. And in my code I have set the textfields cols, JTextField field = new JTextField(10); like so. But do all text textfields have to be an event in its self. I have been reading Head First Java and Java for dummies and nothing was said to make a textfield or a textarea an event? I use buttons in the event, to get text from source and all works fine.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2154
    
    7
1) add the components to the frame
2) then invoke frame.setVisible(...)
Adam Burda
Ranch Hand

Joined: Jul 19, 2011
Posts: 40
I have no clue how to put this. The frame is made, it has a title, size, visible, defalutClose, with JPanel added to it. The panel has a button, when i run it the window shows the button, then when i add a textfield or a textarea to the panel and run it, the window shows up on the screen with nothing on it, no button or textfield, unless i grab one of the sides of the window with my curser to expand or to shrink the window then the button and the textfield appears. Note the i preset the window size to what ever such as 400,600 and so on.
Adam Burda
Ranch Hand

Joined: Jul 19, 2011
Posts: 40
Ok here is an app this app works, but only when I expand the window my self.

mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

try setting the JPanel visible

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38041
    
  22
You only need to call setVisible on the frame, but you should do that last, after adding the panel. (Otherwise you could use validate/revalidate on the frame).
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2154
    
    7
I have no clue how to put this.


What part of my answer was confusing?

I gave you the order in which your code needs to be executed.

Did you do what I suggested???

try setting the JPanel visible


There is no need to do that, a panel is visible by default. Did you read my suggestion???
Adam Burda
Ranch Hand

Joined: Jul 19, 2011
Posts: 40
Ok i understand that the panel is visible while the frame is set to true. But arnt the components set to the panel then in turn set to the frame? Or does the panel need to be part of the frame such as



becouse if so, I still get the same thing, a blank window.
Adam Burda
Ranch Hand

Joined: Jul 19, 2011
Posts: 40
Ok I feel like noob... when i put the panel its self with in the frame and setVisible to true at the end of the code, it all works. Thank you. But how do you make show while the panel is outside of the frame class as my code above?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> becouse if so, I still get the same thing, a blank window.

then why post code you're just typing into the browser:

this.setDefalutCloseOperation

Defalut??

if you really want help, and not just trying to have a bit of fun,
post the code that is not working
Adam Burda
Ranch Hand

Joined: Jul 19, 2011
Posts: 40
Yes sir I do want help. I am not here to have any fun at all. I have been trying to study java off and on for the past 2 years. In hope's that one day i may find employment in programming. I have also been taking classes in programming html, java script, vb.net, sql, alice, and my next class is oop in java. I have bought a few books on java such as Head First, java for dummies - 9 books in one and Ivor Horton's Beginning java. I can do a lot in the console window, but im trying to grasp the frame and panels. In one of my books. I read that after the frame class you can make a panle class. Thats why the question why am i getting a blank window. How do i set it to visible(true) while the panel is in its own class? And not get a blank window.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Yes sir I do want help.

best help is obtained by posting exact code (ctrl-c --> ctrl-v), not pseudo-code.

if you can add/show (e.g.) a JTextField in the frame, then adding/showing your own panel is (almost) exactly the same.

java needs to know where the .class file is.
In the case of the textfield, 'import javax.swing.JTextField;' or 'import javax.swing.*;' tells java where it is.
java looks in the current directory/folder as well, so here's a very simple example of classes in the same directory

create a .java file and call it MyPanel.java
copy this code into that file, save/compile, if OK close the file



now create another .java file, call it MyFrame.java (must be in the same directory/folder as MyPanel.java)
copy this code into that file, save/compile, now run this one (it has a main());



probably your next step is to look into 'Packages', where you might have numerous class files.
Digen Mahara
Greenhorn

Joined: Dec 23, 2011
Posts: 23

Adam Burda wrote:I am running windows 7 64bit Home Premium with an intel core i3 and 4GB of ram. I run my java code in eather prompt or i use JCreator LE. Every time i wright an app I get a blank frame or a blank panel. But only when I put in a JTextArea or a JTextField. Buttons, CheckBoxes, and Raido Buttons all show fine. But when i add a textfield the program compiles fine then i run it. The window pop's up, but nothing on it. Unless i grab one of the sides to adjust the size of the window myself, bigger or smaller. Then the window displays the buttons, textfield...... I have tryed resizing, and using other layouts. I have no clue what the bug is. This happens with any and all code I wright.



It is a problem that most of us face

You should read the Java API.
You can also use validate() and repaint() method
But I have seen such problems with Applets
take this Sample code where i got such problems



Sorry for such a big code but this is actually where I faced the problem for JCombobox an d JButtons to appear try it and there are many bugs and it is not a full fledged Calculator
But should help you understand
Please Quote if any mistakes as I have Edited it


To every Tunnel there is always a way out
So keep Trying...
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Digen Mahara wrote:It is a problem that all of us face.
Try to use the getContentPane() mathod this should help you <google it> you will get something that may help you

Absolutely meaningless advice, that also suggests you are not familiar with the API.

How is getContentPane() supposed to help here? Why should it be necessary to search the net and not read the API?


luck, db
There are no new questions, but there may be new answers.
 
jQuery in Action, 2nd edition
 
subject: Blank Frame or Panel
 
Similar Threads
organising panels
threads for GUI and command-line
TextArea components
Can't close window
JTable