1

我正在建立一个小对话框。我从 gradle 构建脚本中使用 Groovy。该对话框由一个 JList、一个 JTextField 和一个 JButton 组成。

该列表填充了文件的名称。有很多文件,所以我只想显示 5 个文件和一个 scollbar 来遍历列表。我试图设置 visibleRowCount 但它仍然显示所有行。

new SwingBuilder().edt {
        dialog(modal: true,             // Otherwise the build will continue running before you closed the dialog
            title: 'Enter program name',// Dialog title
            alwaysOnTop: true,          // pretty much what the name says
            resizable: true,           // Don't allow the user to resize the dialog
            locationRelativeTo: null,   // Place dialog in center of the screen
            pack: true,                 // We need to pack the dialog (so it will take the size of it's children
            show: true                  // Let's show it
            ) {
                vbox { // Put everything below each other
                    label(text: "Program Name:")
                    list(id:"programName", items: progNames, visibleRowCount: 8)
                    label(text: "Start Rule Name:")
                    input = textField(id: 'ruleName', text: startRuleName)

                    button(defaultButton: true, text: 'OK', actionPerformed: {
                        testProgram   = programName.selectedValuesList
                        startRuleName = ruleName.text
                        dispose() // Close dialog
                    })
                }
            }
        }

如何限制可见行数?

4

1 回答 1

2

您只需要将调用包装list在一个scrollPane节点中,即:

new groovy.swing.SwingBuilder().edt {
        dialog(modal: true,             // Otherwise the build will continue running before you closed the dialog
            title: 'Enter program name',// Dialog title
            alwaysOnTop: true,          // pretty much what the name says
            resizable: true,           // Don't allow the user to resize the dialog
            locationRelativeTo: null,   // Place dialog in center of the screen
            pack: true,                 // We need to pack the dialog (so it will take the size of it's children
            show: true                  // Let's show it
            ) {
                vbox { // Put everything below each other
                    label(text: "Program Name:")
                    scrollPane {
                        list(id:"programName", items: progNames, visibleRowCount: 8)
                    }
                    label(text: "Start Rule Name:")
                    input = textField(id: 'ruleName', text: startRuleName)

                    button(defaultButton: true, text: 'OK', actionPerformed: {
                        testProgram   = programName.selectedValuesList
                        startRuleName = ruleName.text
                        dispose() // Close dialog
                    })
                }
            }
        }
于 2017-03-19T20:39:48.597 回答