Results 1 to 4 of 4
- 06-03-2008, 11:14 AM #1
Member
- Join Date
- Mar 2008
- Posts
- 20
- Rep Power
- 0
Problem here guys: Set location or setBounds
Hi I want to build a small interactive prg but I'm having a problem with the components, I want to attain precision such that the labels match with the corresponding JTeatFields, now:
- Must I use a Layout manager or do I Let the default take place
- How comes if I try SetLocation or SetBound there is no effect the components just pile up and I see the last one.
- how is it that setEchoChar('*'); gives an error
Here's the code for my Frame1
Java Code:package Frame1; import javax.swing.*; import java.awt.*; import java.io.*; public class Frame1 extends Frame{ JFrame f1; JLabel lb1; JLabel lb2; JTextField ff1; JTextField ff2; JButton bt1; JButton bt2; public Frame1() { f1 = new JFrame("Frame 1"); f1.setLayout(new FlowLayout()); f1.setSize(600, 600); lb1 = new JLabel("Enter Username :"); lb2 = new JLabel("Enter Password :"); ff1 = new JTextField(25); ff2 = new JTextField(25); ff2.setEchoChar('*'); bt1 = new JButton("OK"); bt1.setMnemonic('O'); bt2 = new JButton("Quit"); bt2.setMnemonic('Q'); f1.add(lb1); lb1.setLocation(50, 50); //lb1.setBounds(50,50,80,20); f1.add(ff1); ff1.setLocation(120, 50); //ff1.setBounds(120,50,80,20); f1.add(lb2); lb2.setLocation(50, 180); //lb2.setBounds(50,180,80,20); f1.add(ff2); ff2.setLocation(120, 180); //ff2.setBounds(120,180,80,20); f1.add(bt1); bt1.setLocation(50, 280); //bt1.setBounds(50,280,80,20); f1.add(bt2); bt2.setLocation(120, 280); //bt2.setBounds(120,280,80,20); f1.setVisible(true); } public static void main (String[] args) { new Frame1(); } }The dream of being a legend has just begun!
- 06-03-2008, 01:53 PM #2
As far as i know,I want to attain precision such that the labels match with the corresponding JTeatFields, now:
- Must I use a Layout manager or do I Let the default take place
- How comes if I try SetLocation or SetBound there is no effect the components just pile up and I see the last one.
setBounds/setLocation will only take effect if your container has no layout or null.
But If you really need to use layout, GridBagLayout/GroupLayout may fit your needs. (Newer version of NetBeans used that)
and you can also manage the components' behavior if its container resized.
That's the advantage, but it takes time just to code the GUI.
Plus,(Base of what i've observed before) it takes a little bit of time at start-up(executing the application).
For about 600-900 milliseconds for 20 components and a container.freedom exists in the world of ideas
- 06-03-2008, 06:45 PM #3
Member
- Join Date
- Mar 2008
- Posts
- 20
- Rep Power
- 0
How about setEchoChar
Hi after removing the layout manger setBounds works but not etLocation however the setEchoChar still gives me errors and the component disappear after I run the application.
The dream of being a legend has just begun!
- 06-03-2008, 07:19 PM #4
It depends actually...Hi after removing the layout manger setBounds works but not setLocation
setBounds method already covered the task of setLocation method.
for example, by using setBounds(x,y,w,h);
first 2 will set the x/y location of that component with respect to its container.
second 2(w/h) will set the size of that component
when invoking first the setBounds method before setLocation,
setLocation takes effect. (x/y will be useless)
if reverse invocation, setLocation will be useless.
I would suggest not to use that kind of implementation, instead use JPasswordField.however the setEchoChar still gives me errors and the component disappear after I run the application.freedom exists in the world of ideas
Similar Threads
-
Hi Guys
By gibsonsydsa in forum IntroductionsReplies: 1Last Post: 02-06-2008, 06:36 AM -
Hie guys
By heat84 in forum IntroductionsReplies: 1Last Post: 12-20-2007, 06:50 AM -
Hello guys
By tharindu in forum IntroductionsReplies: 0Last Post: 11-26-2007, 07:58 AM -
how to get the location of some button
By mary in forum Java 2DReplies: 2Last Post: 08-05-2007, 04:02 AM -
Help Me Out Guys
By prince24 in forum New To JavaReplies: 10Last Post: 07-13-2007, 04:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks