Re: How to size a JTextField according to a fixed string length?
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Fri, 28 Oct 2005 15:56:17 GMT
"Casper Bang" <casper@xxxxxx> wrote in message
news:43624468$0$38734$edfadb0f@xxxxxxxxxxxxxxxxxxxxxxx
> How do I size a JTextField, such that I know for a fact that it can
> display a certain string lenght? I do not want the field to grow or shrink
> according to content, it should be fixed upon initial creation.
>
> Thanks in advanced,
> Casper
If it is not mission critical that the string can be displayed, use the
setColumns method. It assumes that in the font being used, 'm' us the widest
character, and sizes the JTextField to be able to fit the string composed of
N 'm's appended together.
If it IS mission critical, you will need to get a hold of the Font
object, and render every character into an off-screen buffer, measure their
widths, and the use the maximal width as the width of a single column,
multiply it by how long you string is, set the width of the JTextArea to
that. There are approximately one million Unicode characters.
- Oliver
.
- References:
- How to size a JTextField according to a fixed string length?
- From: Casper Bang
- How to size a JTextField according to a fixed string length?
- Prev by Date: Re: problem with JTabbedPane and stateChangeEvent and set busy cursor
- Next by Date: Re: Mouse clicks within JTable unreliable
- Previous by thread: How to size a JTextField according to a fixed string length?
- Index(es):
Relevant Pages
|