首页 文章

在Dialog中滚动文本不起作用

提问于
浏览
3

我正在使用以下代码创建一个Dialog:

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构建器,但不使用此对话框 .

1 回答

  • 2

    我想我找到了答案 - 使用Dialog中的show方法,如:

    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");
    

    需要一些调整但滚动现在可以工作 . 抱歉,如果我浪费了任何人的时间 .

    后来:无法“调整”上面的代码,所以如果它帮助了其他人,我终于在Dialog中使用以下内容获得了可滚动文本:

    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);
    

相关问题