Scrolling text in a dialog doesn't work
I am creating a dialog with the following code:
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);
The DialogText contains several lines that need to be scrolled on low resolution devices, but the code above does not achieve this. What did I miss? Also tried to do SpanLabel scrolling, but it didn't work. Just moved this project from Eclipse to Netbeans (new to this). Using an old graphics editor, but not for this dialog.
+3
source to share
1 answer
I think I found the answer - use show methods in the dialog, as in:
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");
Requires a bit of tweaking, but scrolling now works. I apologize if I wasted any time.
Later: it is not possible to "customize" the above code, so if it helps someone else, I finally got the scrollable text in the dialog using:
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);
+2
source to share