• 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

empty frame

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.awt.*;
public class AFrame extends Frame {
public AFrame() {
super("A Frame");
add(new Button("A"));
add(new Button("B"));
setVisible(true);
setSize(500,500);
}
public static void main(String ar[])
{
new AFrame();
}
}
Why does this code display an empty frame?
Am I missing something very obvious?
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because the default LayoutManager for Forms is BorderLayout and you aren't specifying any position (north, south, etc) in your add. Try changing the LayoutManager to FlowLayout before adding the buttons.
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Gautam
You must set size of frame and then show it. Try this:
import java.awt.*;
public class AFrame extends Frame {
public AFrame() {
super("A Frame");
add(new Button("A"));
add(new Button("B"));
setSize(500,500);
setVisible(true);
}
public static void main(String ar[]) {
new AFrame();
}
}
It will show button B, which occupies whole frame
Regards,
Jamal Hasanov
www.j-think.com
 
Jamal Hasanov
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thomas wrote :

Because the default LayoutManager for Forms is BorderLayout and you aren't specifying any position (north, south, etc) in your add. Try changing the LayoutManager to FlowLayout before adding the buttons.


Thomas, you're not right - problem is in setSize()/setVisible() consistency. "North","South" and etc. are not the reason of problem.
Jamal Hasanov
www.j-think.com
 
Gautam Sewani
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks jamal,but whats the underlying reason behind this thing?
And why is it that when I maximize the empty frame, the button appears.
And why is it that no tutorial covers this topic??
 
Jamal Hasanov
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gautam,
When you maximize this frame, the following actions are done:
1. change frame's size - setSize(max,max);
2. redraw it.
It's similar to your code:
setSize(500,500);
setVisible(true);
Button also appears when you resize the frame
Maybe there are some redrawing problems, because when you minimize/restore this frame - it's still empty.
I can suggest you to read RHE or KM about frame.
With best regards,
Jamal Hasanov
www.j-think.com
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a way to "update" the frame use the doLayout() method, like this:

who said buttons don�t get greedy?
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the default position is CENTER
 
reply
    Bookmark Topic Watch Topic
  • New Topic