Blackberry Java : Caret없이 텍스트 필드 *?
-
06-07-2019 - |
문제
나는 간병이 표시되지 않는 편집 불가능한 텍스트 필드 (또는 서브 클래스)를 원합니다. 또는 나는 멀티 라인 라벨 필드를 원한다. 이것들 중 하나가 가능합니까?
해결책
초점 커서가없는 텍스트 필드
TextField readOnly = new TextField(NON_FOCUSABLE);
readOnly.setText("Read only, no carret");
add(readOnly);
Textfield DrawFocus 재정의
텍스트가 화면에 맞지 않으면 텍스트 필드에서 DrawFocus 메소드를 무시할 수 있으므로 스크롤을 사용할 수 있습니다.
TextField readOnly = new TextField(READONLY)
{
protected void drawFocus(Graphics graphics, boolean on) {}
};
Nullfields로 분리 된 TextFields
다른 옵션은 NullFields로 분리 된 여러로 텍스트 필드를 나누는 것입니다.
class Scr extends MainScreen {
public Scr() {
String text = "Lorem ipsum dolor sit amet, consectetuer "
+ "adipiscing elit, sed diam nonummy nibh euismod "
+ "tincidunt ut laoreet dolore magna aliquam erat "
+ "volutpat. Ut wisi enim ad minim veniam, quis "
+ "nostrud exerci tation ullamcorper suscipit "
+ "lobortis nisl ut aliquip ex ea commodo consequat. "
+ "Duis autem vel eum iriure dolor in hendrerit in "
+ "vulputate velit esse molestie consequat, vel "
+ "illum dolore eu feugiat nulla facilisis at vero "
+ "eros et accumsan et iusto odio dignissim qui "
+ "blandit praesent luptatum zzril delenit augue "
+ "duis dolore te feugait nulla facilisi.";
text = addScrollText(text, 150);
}
private String addScrollText(String text, int partSize) {
while (0 < text.length()) {
int len = Math.min(partSize, text.length());
TextField readOnly = new TextField(NON_FOCUSABLE);
readOnly.setText(text.substring(0, len));
add(readOnly);
add(new NullField());
text = text.substring(len);
}
return text;
}
}
멀티 린 래 필드
Labelfield의 다중 텍스트, Newline Escape 캐릭터를 사용하십시오.
String text = "first line \nnew line \nanother line";
LabelField multiLine = new LabelField(text);
add(multiLine);
다른 팁
예, 각 UI 요소의 페인트 방법을 무시할 수 있습니다.
An example:
public class WhiteLabelField extends LabelField
{
public WhiteLabelField()
{
super();
}
public WhiteLabelField(ObjectGroup text)
{
super(text);
}
public WhiteLabelField(Object text, long style)
{
super(text, style);
}
public void paint(Graphics _g)
{
_g.setColor(Color.WHITE);
super.paint(_g);
}
// Custom
public void setSmallFontSize()
{
setFont( Font.getDefault( ).derive( Font.PLAIN, 16 ));
}
}
당신은 또한 사용할 수 있습니다 RichTextField
스타일로 Field.NON_FOCUSABLE
그리고 당신은 당신이 원하는 것을 가질 것입니다.
제휴하지 않습니다 StackOverflow