This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Layout

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class FrameTest extends Frame{
public FrameTest(){
super("FrameTest");
setSize(300,400)
setVisible(true);
Componrnt b=new Button("B");
Component c=new Button("C");
add(c);
add(b);
}
public static void main(String srgs[]){
FrameTest f=new FrameTest();
}
}
Answer given empty window is displayed.
I feel button B should occupy the whole frame
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Neha,
The trick is to know how LayoutManager2 interface works. The layout manager, BorderLayout in this case, only lays out the components that it knows about at the time that it is validated. The setVisible method call internally calls validate so that the layout can manage its children. At that time, no children are present so the frame contains nothing.
Adding children later will not change the displayed layout until it is validated again. Since you have not called validate explicitly or setVisible again the new children won't appear.
Try adding a call to validate() at the end of the constructor to see what happens.
Regards,
Manfred.
 
Neha Sawant
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Manfred,
I thought the steps were
1. construct a frame
2. set a layout
3 and then add components.
this implies to Layout Manager2.
If i add components first and then set a layout then i will get an empty frame.
Please explain what the rules are and where do the above mentioned rules apply
Neha
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that too.
After code, compile and ran it, it shows an empty window.
Here's why:
1.- The frame is made visible before the buttons are added, so when it is drawn there's no buttons to show.
2.- The buttons are added to the frame, but as the frame has already been drawn thus they are not showed, if you resize the window with the mouse the B button will appear occupying the whole frame this is because when the frame is changes its size
paint method is called and the button that were added is painted too.
as demo here's a modified code:

Originally posted by Neha Sawant:
public class FrameTest extends Frame{
public FrameTest(){
super("FrameTest");
setSize(300,400)
setVisible(true);
Componrnt b=new Button("B");
Component c=new Button("C");
add(c);
add(b);
}
public static void main(String srgs[]){
FrameTest f=new FrameTest();
}
}
Answer given empty window is displayed.
I feel button B should occupy the whole frame



[This message has been edited by Zkr Ryz (edited November 07, 2001).]
 
Neha Sawant
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i think you are right.
well for the button to be displayed at first attempt the setVisible should be after adding buttons.
Am i right?
Neha
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!