0

我的 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]);
4

1 回答 1

0

我想到了。我看到我的 setPreferredSize 选项非常小,这就是 JScrollPane 打开很小的原因。我的 JTextArea 使用相同的 displayDimension,但在创建 JTextArea 时,我为 JTextArea 建立了更大的尺寸。由于某些未知原因,我的 JTextArea 不接受较新的 setPreferredSize 并保持实例化期间建立的大小。我使用以下方法调整了 JScrollPane 的大小;

  displayScroller.setPreferredSize(new Dimension(640,90)); 

现在工作正常。

于 2014-10-11T16:15:34.990 回答