• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BorderLayout

 
umang bhartia
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the code given below, why it is printing button on east? I think that it is printing the button in all direction one by one shows only the last one as only one instence of the Button object is created.Please let me know the correct reason of this output.
public class Q16 extends Applet
{
Button okButton = new Button("Ok");
public void init()
{
setSize(300,300);
setLayout(new BorderLayout());
add(okButton,"North");
add(okButton,"South");
add(okButton,"Center");
add(okButton,"East");
}
}
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know how to post a link to another post. I asked this same question yesterday. the title of the thread is "Majii exam question 20"
 
umang bhartia
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks i went throw your Post, but now my Question is that how it will work, i mean to say is that will it first print it on "North" and then removing it again printing on "South" again removing it and it goes on till the last one is executed. Is it so? as i want to know how the working goes.
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is how it appears to work to me.
 
sirisha parimi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
actually there is one component to be added .so it is added on the last specified location and made visible.
( and for a borderlayout when only one component is added it occupies full and u cann't make out which which side it is added.)

[This message has been edited by sirisha parimi (edited December 19, 2000).]
 
sunilkumar ssuparasmul
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess umang u r right . i tried it printing System.out.println("some val") after each add method it prints all the four. so it must be putting button in north first and then removing it and putting in subsequent positions. so the last posted is displayed to us.
If i am wrong plz correct

thanks,
sunil.s
 
Baskaran Srinivasan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah. Looks like it takes the last instance of Button object and prints it in that corresponding location.
But if you create different instances of Button object like
okButton, ok1Button, ok2Button etc.,, and keep adding these
instances across N,S,W,E and Center U will get what u wanted.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic