Kotlin DSL UI: scroll pane takes wrong height of MemberSelectionTable

Answered

I'm trying to add members selection to my form, let's take simplest one:

val table = MemberSelectionTable(members, null)
panel {
row {
scrollPane(table)
}
}

Unfortunately, scroll pane height becomes table height minus header and one of member is not shown.

What can I do here?

6 comments
Comment actions Permalink

Sorry this got lost. What does MemberSelectionTable extend from?

0
Comment actions Permalink

It's com.intellij.refactoring.ui.MemberSelectionTable and it extends AbstractMemberSelectionTable<PsiMember, MemberInfo>

0
Comment actions Permalink

Sorry for delay.

I failed to reproduce this behavior in 2020.2.4 with this simple test action/dialog on macOS. Could you please specify your IDE version and OS? Does this test code work on your system? Thanks.

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.refactoring.ui.MemberSelectionTable
import com.intellij.refactoring.util.classMembers.MemberInfoStorage
import com.intellij.ui.layout.panel
import javax.swing.JComponent

class TestDialogAction : AnAction() {

override fun actionPerformed(e: AnActionEvent) {
val project = e.project!!
val wrapper = object : DialogWrapper(project) {
init {
title = "Test Dialog"
super.init()
}

override fun createCenterPanel(): JComponent? {

val clazz = JavaPsiFacade.getInstance(project)
.findClass("javax.swing.JTree", GlobalSearchScope.allScope(project))!!

val storage = MemberInfoStorage(clazz) {
println(it.name)
true
}
val table = MemberSelectionTable(storage.getClassMemberInfos(clazz), null)
return panel() {
row {
scrollPane(table)
}
}
}
}
wrapper.show()
}
}
0
Comment actions Permalink

In your case members count is high enough to add scroll anyway. If you limit it, for instance, to 4:

var count = 0
val storage = MemberInfoStorage(clazz) {
count++ < 4
}

you will see that only 3 members shown.

if I expand it by dragging with mouse, all 4 members shown and scroll disappears:

 

PS 2020.2.4 Ultimate, Windows 10 Pro

0
Comment actions Permalink

AbstractMemberSelectionTable constructor specifies "default' size/number of visible rows. You can override this in your code explicitly:

setPreferredScrollableViewportSize(JBUI.size(400, -1));
setVisibleRowCount(12);

 

0
Comment actions Permalink

Thanks!

setVisibleRowCount doesn't work as expected, looks like header height still not used in calculation. I will use workaround with preferredScrollableViewportSize and calculate height with header manually.

0

Please sign in to leave a comment.