Skip to content

Commit 8baf8f3

Browse files
class to fix resizing issues of JTextArea
when putting JTextArea into JPanel and JPanel into JScrollPane
1 parent 0b0b508 commit 8baf8f3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.utplsql.sqldev.ui.runner
17+
18+
import java.awt.Rectangle
19+
import javax.swing.JPanel
20+
import javax.swing.Scrollable
21+
22+
/*
23+
* Fixes resizing issues of JTextArea when put into JPanel and JPanel into JScrollPane
24+
* Solution is based on https://stackoverflow.com/questions/15783014/jtextarea-on-jpanel-inside-jscrollpane-does-not-resize-properly/15786939
25+
*/
26+
class ScrollablePanel extends JPanel implements Scrollable {
27+
28+
override getPreferredScrollableViewportSize() {
29+
return super.getPreferredSize()
30+
}
31+
32+
override getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
33+
return 0
34+
}
35+
36+
override getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
37+
return 0
38+
}
39+
40+
override getScrollableTracksViewportWidth() {
41+
return true
42+
}
43+
44+
override getScrollableTracksViewportHeight() {
45+
return false
46+
}
47+
}

0 commit comments

Comments
 (0)