• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

predefine the button's location

 
Akshat Shree Ram Pandey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys(or gals) I am a new member of this cool ranch..
Actually I created a basic button applet, but I'm tired searching commands how to place the location of a button such that it appears at the start at some specific x and y location..
All commands I've tried have failed.. Here's my code:

I actually want to place the X button at some desired x and y location like 50,90 but how can I!?
Kindly help me, if you don't understand me please reply and I will try my best to make you understand how can you fix my problem.
Thanks a lot
- ASRP.
 
Piet Souris
Rancher
Posts: 1518
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Akshat,

Welcome!

if you really want to put your buttons at any x,y position you like, a null layout comes to mind.
However, using a null layout comes with some big drawbacks. Maybe if you can explain more details
about the desired layout, we could give some appropriate tips. But foremost: have a look at the
Oracle tutorial about LayoutManagers

But about the null layout:

in your init() method, add the line:
It means that you take complete responsibility for sizing and placing your components.
For instance: create your vega button like this:


 
Akshat Shree Ram Pandey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Piet, thanks a lot! I tried to ask the same question at stackoverflow and some petty perfectionists came and started saying bullcraps, criticizing me on my old aged programming, saying that pre defined
button is useless, now I ain't goin there, Big Moose4Questions!
Thanks a lot! I just can't express my gratefulness
- ASRP
 
Piet Souris
Rancher
Posts: 1518
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome!   
 
Akshat Shree Ram Pandey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Piet!
I tried enabling the setBounds on a button non, here's my updated code :-

But what I get as an applet output is a blank page what's my mistake?
 
Piet Souris
Rancher
Posts: 1518
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Akshat,

well, remember I did say that if you use a null layout, you take responsibility for all the sizes and locations of your components?
Now, that's quite a responsibility indeed, and therefore the use of a null layout is not recommended.

As you see in your applet, you do create your buttons, but you do not define any size. You do for the "non" button, but right after that you recreate a new "non".

I would like you to add this method to your applet:



and, when you create your buttons, use this (one example given):



And watch the output of your console: do you notice, after a button is created, what size it has?
And if you do nothing, then you won't see such a button!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic