Re: How to size a JTextField according to a fixed string length?




"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


.



Relevant Pages

  • Re: A Simple BMP Converter
    ... "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal ... Private Sub cmdSysInfo_Click ... Open Registry Key ... > color bar in the color display. ...
    (comp.lang.basic.visual.misc)
  • Re: help collecting data.
    ... Dim GetC As String ... the code in the cell that I want the order numbers(info from column C ... "Otto Moehrbach" wrote: ... display them both, seperated by a comma ...
    (microsoft.public.excel.misc)
  • Re: Output data from multiple records in a table
    ... > Dim rsR As DAO.Recordset ... > Dim strSQL As String ... > such as display it in a textbox on your form. ...
    (microsoft.public.access.modulesdaovba)
  • Need help with GridView and LDAP/GC
    ... I could do the search with GC, and then lookup more ... DirectoryEntry searchRoot = new ... // Add search string if specified. ... // Display Name ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: HUD Text in Virtual Reality Toolbox viewer window
    ... A few people recently asked us how to display continuously changing text in VR Viewer during Simulink simulation. ... You can define a dummy object whose fields correspond to the types of the values you want to display The signal is then sent to virtual scene using the VR Sink block, in VRML file is routed to a script that does the conversion to the text and updates the value of the Text node string displayed in the scene. ...
    (comp.soft-sys.matlab)