1

我创建了一个具有以下顺序的 Swing Frame,JFrame > JPanel > JScrollPane > JTextArea。我正在使用卡片布局将 JPanel 加载到 JFrame 中。

我的问题是滚动条显示不正确(如图所示)。在此处输入图像描述

我的代码如下:

    jTextArea1 = new javax.swing.JTextArea();
    jScrollPane1 = new javax.swing.JScrollPane(jTextArea1);


    jTextArea1.setColumns(15);
    jTextArea1.setEditable(false);
    jTextArea1.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N
    jTextArea1.setRows(3);

    JScrollBar verticalScrollBar = jScrollPane1.getVerticalScrollBar();
    verticalScrollBar.setValue(0);
    jTextArea1.setCaretPosition(0);

    jScrollPane1.setPreferredSize(new java.awt.Dimension(632, 425));



//Group Layout
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                    layout.createSequentialGroup()
                            .addGroup(
                                    layout.createParallelGroup(
                                            javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(
                                                    jPanelBottomPanel,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(
                                                    jLabelImageLogoSAGUpgradeUtility,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE)

                            )
                            .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(
                    layout.createSequentialGroup()
                            .addGroup(
                                    layout.createParallelGroup(
                                            javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(
                                                    layout.createSequentialGroup()
                                                    .addContainerGap()
                                                    .addComponent(jPanelStartInstaller,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addContainerGap()
                                                    )
                                            .addGroup(
                                                    layout.createSequentialGroup()
                                                            .addGap(10, 10,
                                                                    10)
                                                            .addComponent(
                                                                    jCheckBox1)
                                                            .addGap(0,
                                                                    0,
                                                                    Short.MAX_VALUE))
                                            .addGroup(
                                                    javax.swing.GroupLayout.Alignment.LEADING,
                                                    layout.createSequentialGroup()
                                                            .addContainerGap()
                                                            .addGroup(
                                                                    layout.createParallelGroup(
                                                                            javax.swing.GroupLayout.Alignment.LEADING,
                                                                            false)
                                                                            .addGroup(
                                                                                    layout.createSequentialGroup()
                                                                                            .addGap(0,
                                                                                                    0,
                                                                                                    0)
                                                                                            .addComponent(
                                                                                                    jScrollPane1,
                                                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                    0,
                                                                                                    Short.MAX_VALUE))
.addGap(5)
                                                                            .addComponent(
                                                                                    jPanel5,
                                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                    javax.swing.GroupLayout.PREFERRED_SIZE))))
                                                                                    .addContainerGap())
    );
    layout.setVerticalGroup(layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                    javax.swing.GroupLayout.Alignment.TRAILING,
                    layout.createSequentialGroup()
                            .addComponent(jLabelImageLogoSAGUpgradeUtility,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(8, 8, 8) 
                            .addComponent(jPanel5,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(
                                    javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jScrollPane1,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 0, Short.MAX_VALUE)
                            .addComponent(jPanelStartInstaller,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jCheckBox1)
                            .addComponent(jPanelBottomPanel,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            ));
4

1 回答 1

0

对于您的评论,

...如果是 Nibus 的外观和感觉,那么我需要更改代码的外观和感觉...

你需要这个,

UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");  

也看看这个:如何设置外观

于 2012-05-09T14:09:47.007 回答