• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Blank Frame or Panel

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) add the components to the frame
2) then invoke frame.setVisible(...)
 
Adam Burda
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok here is an app this app works, but only when I expand the window my self.

 
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try setting the JPanel visible

 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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.
 
Greenhorn
Posts: 23
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic