Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

setLocation does not work

Thread view: 
Jack - 04 Nov 2005 21:44 GMT
Please compile the following code with Javac.
Look at the objects in your browser and you will see that they dont move.
Why?
What can I do to reposition these objects?

import java.awt.*;
import java.applet.Applet;

public class ListSimpleTest extends Applet {
 public void init() {
   List list = new List(5, false);
   list.add("Seattle");
   list.add("Washington");
   list.add("New York");
   list.add("Chicago");
   list.add("Miami");
   list.add("San Jose");
   list.add("Denver");
   add(list);

   list.setSize(400, 420);

   list.setName("This is a name.");

   int height = list.getHeight();
   int width  = list.getWidth();

   TextField f1 = new TextField("1111");
   f1.setLocation(10, 10);
   add(f1);

   TextField f2 = new TextField("1111");
   f2.setLocation(20, 20);
   add(f2);

   TextField f3 = new TextField("1111");
   f3.setLocation(30, 30);
   add(f3);

   TextField f4 = new TextField("1111");
   f4.setLocation(80, 80);
   add(f4);

   f1.setText(Integer.toString(height));
   f2.setText(list.getName());

   f3.setText(Integer.toString(f2.getX()));
   f4.setText(Integer.toString(f2.getY()));

//http://java.sun.com/developer/onlineTraining/awt/contents.html#AWTScrollbar
 }
}
Andrew Thompson - 04 Nov 2005 22:07 GMT
> Please compile the following code with Javac.

Thanks for the offer.  No need.

> Look at the objects in your browser and you will see that they dont move.
> Why?

You are fighting the layout manager.

The two 'solutions' to this are as follows..
1) use a NullLayout[1]
2) learn to use layouts to achieve the effect you need.

[1] 'cleverly' obscured, since that is not a solution.

> What can I do to reposition these objects?

Two recommendations
- Do the Layout tutorial (part of the Swing tutorial, AFAIR)[2]
- Post GUI questions to the group specialised for them[3], as
you get a lot of yob c.l.j.programmers that *think* they are
competent to answer GUI qns. (but aren't).

[2] Both linked from the GUI FAQ, posted regularly to..
[3]  <http://www.physci.org/codes/javafaq.jsp#cljg>

HTH
Andrew Thompson - 04 Nov 2005 22:19 GMT
> - Post GUI questions to the group specialised for them[3], as
> you get a lot of yob c.l.j.programmers that *think* they are
> competent to answer GUI qns. (but aren't).

Oh, I see you are already ahead of me there, but..
Please refrain fom multi-posting.
<http://www.physci.org/codes/javafaq.jsp#xpost>

[ Check out the tutorials I pointed you toward, or as well,
Monique Y. M. just made a post to the (c.l.j.gui) group
linking to two excellent layout tutorials - check them out. ]
Benji - 04 Nov 2005 22:09 GMT
> Please compile the following code with Javac.
> Look at the objects in your browser and you will see that they dont move.
> Why?
> What can I do to reposition these objects?

you have to set the layout manager to null before you can absolutely
position objects like that.

e.g. this.setLayout(null);

I wouldn't use a null layout, though.  Try looking up "LayoutManager
example" on google.

Or, since I know Roedy will do it, I'll save him the trouble.  =)

http://mindprod.com/jgloss/layoutmanager.html

Signature

Of making better designs there is no end,
 and much refactoring wearies the body.

Andrew Thompson - 04 Nov 2005 22:23 GMT
> you have to set the layout manager to null..

Aaaaargh!

Benji, intil you understand why that is such poor advice for x-plat,
x-version, multi-plaf GUI's on a variety of screen resolutions and font
sizes, please refrain from giving GUI advice.

If you really wish to hone your GUI building skills, a good group
to read is c.l.j.gui (mentioned elsewhere in this thread, in a post
in which I warn the OP not to take advice from c.l.j.programmers
..and thinking of that very advice).
Benji - 04 Nov 2005 22:33 GMT
> in which I warn the OP not to take advice from c.l.j.programmers
> ..and thinking of that very advice).

I told him that he shouldn't use a null layout, and should use layout
managers.  How exactly was that bad advice?

Signature

Of making better designs there is no end,
 and much refactoring wearies the body.

Andrew Thompson - 04 Nov 2005 23:09 GMT
>>in which I warn the OP not to take advice from c.l.j.programmers
>>..and thinking of that very advice).
>
> I told him that he shouldn't use a null layout, and should use layout
> managers.  How exactly was that bad advice?

Ummm... My bad for 'going off' when I saw that first line.

Sorry for the wasted bandwith.

[ I must cut down on them dang whiteboard markers.  ;-) ]
Daniel Dyer - 04 Nov 2005 22:34 GMT
>> you have to set the layout manager to null..
>
[quoted text clipped - 3 lines]
> x-version, multi-plaf GUI's on a variety of screen resolutions and font
> sizes, please refrain from giving GUI advice.

To be fair, that wasn't his recommended advice, he was just explaining why  
the original poster's code didn't work and then suggested to use a layout  
manager (so we're all in agreement there).

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk

Jack - 05 Nov 2005 03:10 GMT
yeah concentrate on solving my code problem

>>> you have to set the layout manager to null..
>>
[quoted text clipped - 9 lines]
>
> Dan.
Andrew Thompson - 05 Nov 2005 05:05 GMT
> yeah concentrate on solving my code problem

yeah pay me


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.