Saturday 15 March 2014

swing - Is there a way in Java to set a JTextField's position to be at the start of the text? -



swing - Is there a way in Java to set a JTextField's position to be at the start of the text? -

private jtextfield textfield = new jtextfield(); textfield.settext("10000000000");

if jtextfield small, mine are, it'll show lastly many characters. in case, "00000" if 5 characters can shown given area of text field. want set position automatically start of jtextfield 1 time press separate jbutton. so, in case, want "10000" show.

i have list of multiple jtextfields , jbutton calculations on them , finds things total, prints total in jtextfield, , see lastly part of total can confusing if don't realize it's showing end of text instead of showing beginning.

i looked through ".set***" methods , didn't see alternative this.

take @ jtextfield#setcaretposition

textfield.setcaretposition(0);

you highlight text using...

textfield.setcaretposition(textfield.gettext().length()); textfield.movecaretposition(0);

but jtextfield#selectall simpler...

depending on needs, can "suggest" preferred number of columns field should display, example...

private jtextfield textfield = new jtextfield(15);

or

textfield.setcolumns(15);

this encourage layout managers ensure field sized more appropriate size based on fields needs

java swing jtextfield

No comments:

Post a Comment