Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在对话框中滚动文本不起作用_Java_Codenameone - Fatal编程技术网

Java 在对话框中滚动文本不起作用

Java 在对话框中滚动文本不起作用,java,codenameone,Java,Codenameone,我正在使用以下代码创建一个对话框: Dialog dlg = new Dialog(); dlg.setUIID("AboutDialog"); dlg.setTitle("About"); dlg.setScrollableY(true); dlg.setScrollVisible(true); dlg.setLayout(new BorderLayout()); SpanLabel spl = new SpanLabel(DialogText.aboutTxt[txtItem]); dlg.

我正在使用以下代码创建一个对话框:

Dialog dlg = new Dialog();
dlg.setUIID("AboutDialog");
dlg.setTitle("About");
dlg.setScrollableY(true);
dlg.setScrollVisible(true);
dlg.setLayout(new BorderLayout());
SpanLabel spl = new SpanLabel(DialogText.aboutTxt[txtItem]);
dlg.addComponent(BorderLayout.CENTER, spl);
height = screenHorizontalSize / 9;
width = screenVerticalSize / 10;
Button close = new Button("Close");
close.addActionListener((ee) -> dlg.dispose());
dlg.addComponent(BorderLayout.SOUTH, close);
dlg.show(height, height, width, width);
DialogText包含一些需要在低分辨率设备上滚动的行,但是上面的代码没有实现这一点。我错过了什么?还尝试使SpanLabel可滚动,但没有成功。
刚刚将这个项目从Eclipse移到了Netbeans(这是新的)。使用旧的GUI builder,但不用于此对话框。

我想我找到了答案-使用对话框中的显示方法,如中所示:

Dialog dlg = new Dialog();
dlg.setUIID("AboutDialog");
String title = "About";
String txt = DialogText.aboutTxt[txtItem];
dlg.setLayout(new BorderLayout());
dlg.setScrollableY(true);
dlg.setScrollVisible(true);
dlg.show(title, txt, Dialog.TYPE_INFO, logo_icon, "", "Close");
需要一点调整,但滚动现在工作。 如果我浪费了任何人的时间,我道歉

后来:无法“调整”上述代码,因此为了防止对其他人有帮助,我最终使用以下命令在对话框中获得可滚动文本:

String title = DialogText.getTitleUIID(txtItem);
String txt = DialogText.dialogTxt[txtItem];

Dialog dlg = new Dialog();
dlg.setTitle(title);
dlg.setLayout(new BorderLayout());
TextArea txtArea = new TextArea(txt);
txtArea.setScrollVisible(true);
dlg.add(BorderLayout.CENTER, txtArea);
Button close = new Button("Close");
close.addActionListener((ee) -> dlg.dispose());
dlg.addComponent(BorderLayout.SOUTH, close);
dlg.showAtPosition(0, 0, 0, 0, true);

这里有几个错误
setScrollableY(true)
将被不允许滚动的
BorderLayout
否定。您可以将内容容器放置在边框布局的中心,并使其可滚动或使用长方体Y容器。第一个代码示例创建一个dialog实例,然后使用dialog的静态方法来显示一个完全不同的实例。最后一个示例之所以有效,是因为默认情况下,
TextArea
可以在Y轴上滚动,因此它接管了滚动任务。