我的 JScrollPane 打开但很小。我曾尝试在 JTextArea 和 JScrollPane 上使用 setPreferredSize,但是当我将 JScrollPane 添加到 FlowLayout 面板时,它仍然打开得非常小。如果没有 JScrollPane,我的 JTextArea 会以正确的大小打开。使用 JScrollPane,我得到了一个非常小的 JTextArea。此外,尝试 setBorder 只会导致我的程序挂起。任何帮助,将不胜感激。(我使用的是 Netbeans 8.0.1)
代码输出:
// Create the array manipulator display using JTextArea
JTextArea display = new JTextArea(5, 40);
//private final JScrollPane displayScroller;
JScrollPane displayScroller = new JScrollPane();
// Create arrays for the dimensions of the buttons and displays
int[] dimW ={300, 45, 100, 90, 190, 240, 500};
int[] dimH = {35, 40, 10};
// Declare and initialize the dimensions for the components
Dimension displayDimension = new Dimension(dimW[1], dimH[0]);
// Establish variable for Window and Panel Layout
FlowLayout f1 = new FlowLayout(FlowLayout.CENTER);
row[0] = new JPanel();
row[0].setLayout(f1);
// Create Array Manipulator display area
display.setFont(font);
display.setEditable(false);
display.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
display.setPreferredSize(displayDimension);
display.setLineWrap(true);
display.setWrapStyleWord(true);
// Create display area scroller
displayScroller = new JScrollPane(display);
displayScroller.setPreferredSize(displayDimension);
row[0].add(displayScroller);
add(row[0]);