我创建了一个具有以下顺序的 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)
));