How to for JTextField and JButton..

How can i set the size of the JTextField and getting the words alignment to be in Center format? Can i use JButton, click on it and key in value to be displayed in text form?
[181 byte] By [burpyjaca] at [2007-10-3 3:12:21]
# 1

Hi,

you can change the alignment really simple:

JTextField textField = new JTextField("Your Text");

textField.setHorizontalAlignment(JTextField.LEFT);

textField.setHorizontalAlignment(JTextField.CENTER);

textField.setHorizontalAlignment(JTextField.RIGHT);

The size can be set by

setPrefferedSize(int w, int h)

or try

setColumns(int columns)

L.P.

lukika at 2007-7-14 21:03:16 > top of Java-index,Desktop,Core GUI APIs...
# 2
oh thank you! in that case, is it possible for me to click on the textbox and enter my value(integer number)? insteda of pre-setting my text? how can i do that?
burpyjaca at 2007-7-14 21:03:16 > top of Java-index,Desktop,Core GUI APIs...
# 3
> insteda of pre-setting my text? Read the API. There is a constructor for this.
camickra at 2007-7-14 21:03:16 > top of Java-index,Desktop,Core GUI APIs...
# 4
and is there anything that i need to declare or initialise?
burpyjaca at 2007-7-14 21:03:16 > top of Java-index,Desktop,Core GUI APIs...
# 5
Read the API. Follow the link to the tutorial on "Using Text Components" and try the code yourserlf. How do you expect to learn without trying on your own?
camickra at 2007-7-14 21:03:16 > top of Java-index,Desktop,Core GUI APIs...