You can't change width and font of TextField in Java ME, API Javadocs for this class have nothing related to font (actually, the very word font isn't mentioned in these docs).
If these couldn't be done, I don't think programmers can make their J2ME application look best.
You are right but the reason for this limitation is that TextField and other high level UI API are intended to allow programmers write simple highly portable code (leaving details on what font to use on large/small screen to the system).
This is pretty well explained in lcdui package API docs, in section Structure of the MIDP UI API:
The high-level API is designed for business applications whose client parts run on MIDs. For these applications, portability across devices is important. To achieve this portability, the high-level API employs a high level of abstraction and provides very little control over look and feel. This abstraction is further manifested in the following ways:
- The actual drawing to the MID's display is performed by the implementation. Applications do not define the visual appearance (e.g., shape, color, font, etc.) of the components.
- Navigation, scrolling, and other primitive interaction is encapsulated by the implementation, and the application is not aware of these interactions.
- Applications cannot access concrete input devices like specific individual keys.
In other words, when using the high-level API, it is assumed that the underlying implementation will do the necessary adaptation to the device's hardware and native UI style...
Regarding fonts, of high level UI API classes Choice implementations such as List
and ChoiceGroup
have some capabilities, but these are pretty limited, consult with API docs for details if you are interested.
For fuller access to features you look for, study the "low level" part of the API, described in the package docs referred to above:
This API is designed for applications that need precise placement and control of graphic elements, as well as access to low-level input events. Some applications also need to access special, device-specific features... Applications that program to the low-level API are not guaranteed to be portable, since the low-level API provides the means to access details that are specific to a particular device...
In particular, Graphics class has methods to get and set font - called respectively, getFont
and setFont
.
Note by the way that features provided by Graphics could be "embedded" within Form using CustomItem API.