diff --git a/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt b/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt index a5f0d2aab159..2d87c3f1a6ba 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt @@ -120,6 +120,15 @@ fun CellBuilder.actsAsLabel(): CellBuilder { return this } +internal interface ScrollPaneCellBuilder { + fun noGrowY() +} + +fun CellBuilder.noGrowY(): CellBuilder { + (this as ScrollPaneCellBuilder).noGrowY() + return this +} + fun CellBuilder.withTextBinding(modelBinding: PropertyBinding): CellBuilder { return withBinding(JTextField::getText, JTextField::setText, modelBinding) } @@ -393,8 +402,8 @@ abstract class Cell : BaseBuilder { panel(*constraints) } - fun scrollPane(component: Component, vararg constraints: CCFlags) { - JBScrollPane(component)(*constraints) + fun scrollPane(component: Component, vararg constraints: CCFlags): CellBuilder { + return JBScrollPane(component)(*constraints) } abstract operator fun T.invoke( diff --git a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt index dbd2fc472f78..9cd33e65522c 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt @@ -9,8 +9,8 @@ import com.intellij.openapi.ui.panel.ComponentPanelBuilder import com.intellij.ui.HideableTitledSeparator import com.intellij.ui.SeparatorComponent import com.intellij.ui.TitledSeparator -import com.intellij.ui.components.DialogPanel import com.intellij.ui.UIBundle +import com.intellij.ui.components.DialogPanel import com.intellij.ui.components.Label import com.intellij.ui.layout.* import com.intellij.util.SmartList @@ -418,7 +418,7 @@ class CellBuilderImpl internal constructor( private val builder: MigLayoutBuilder, private val row: MigLayoutRow, override val component: T -) : CellBuilder, CheckboxCellBuilder { +) : CellBuilder, CheckboxCellBuilder, ScrollPaneCellBuilder { override fun comment(text: String, maxLineLength: Int): CellBuilder { row.addCommentRow(component, text, maxLineLength) return this @@ -467,6 +467,13 @@ class CellBuilderImpl internal constructor( override fun actsAsLabel() { builder.updateComponentConstraints(component) { spanX = 1 } } + + override fun noGrowY() { + builder.updateComponentConstraints(component) { + growY(0.0f) + pushY(0.0f) + } + } } private fun getCommentLeftInset(component: JComponent): Int { diff --git a/platform/platform-tests/testData/ui/layout/scrollPaneNoGrow.yml b/platform/platform-tests/testData/ui/layout/scrollPaneNoGrow.yml new file mode 100644 index 000000000000..928be6018939 --- /dev/null +++ b/platform/platform-tests/testData/ui/layout/scrollPaneNoGrow.yml @@ -0,0 +1,35 @@ +layoutConstraints: + fillX: true + gridGapX: + min: &id001 {horizontal: true, unit: 0, value: 0.0} + preferred: *id001 + gridGapY: + min: &id002 {horizontal: false, value: 10.0} + preferred: *id002 + hideMode: 2 + insets: + - {horizontal: false, unit: 0, value: 0.0} + - {horizontal: true, unit: 0, value: 0.0} + - {horizontal: false, unit: 0, value: 0.0} + - {horizontal: true, unit: 0, value: 0.0} +rowConstraints: + constraints: + - align: &id003 {horizontal: false, unit: -1, value: 0.0} + - align: *id003 + count: 2 +columnConstraints: + constraints: + - {} +componentConstrains: + 'JBScrollPane #0': + horizontal: {grow: 100.0} + pushY: 100.0 + spanX: INF + vertical: {grow: 100.0} + wrap: true + 'JBScrollPane #1': + horizontal: {grow: 100.0} + pushY: 0.0 + spanX: INF + vertical: {grow: 0.0} + wrap: true \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt index 04c2364fa4df..5cbe6b31ea89 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt @@ -8,6 +8,7 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.TestName import javax.swing.JPanel +import javax.swing.JTable /** * Set `test.update.snapshots=true` to automatically update snapshots if need. @@ -82,5 +83,19 @@ abstract class UiDslTest { doTest { titledRow() } } + @Test + fun scrollPaneNoGrow() { + doTest { + panel { + row { + scrollPane(JTable()) + } + row { + scrollPane(JTable()).noGrowY() + } + } + } + } + protected abstract fun doTest(panelCreator: () -> JPanel) } \ No newline at end of file