2012-05-09 38 views
1

我創建了一個具有以下序列的Swing框架:JFrame> JPanel> JScrollPane> JTextArea。 我正在使用卡片佈局將Janel加載到JFrame中。滾動窗格(其中有textArea)的滾動條在java swing GUI中沒有正確顯示

我的問題是滾動條顯示不正確(如圖所示)。 enter image description here

我的代碼如下:

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) 
          )); 
+0

FYI:一個JFileChooser內的滾動條也沒有出現不當,當單擊按鈕時是越來越打開一個JFileChooser ... – merlachandra

+2

我認爲沒有錯與那些滾動條。這只是Nimbus的外觀和感覺滾動條(見例如[這個博客文章與Nimbus圖像](http://www.thectoblog.com/2010/01/nimbus-look-and-feel.html)) – Robin

+0

謝謝羅賓,如果是Nibus的外觀和感覺,那麼我需要改變我的代碼的外觀和感覺...非常感謝,我爲這個愚蠢的東西嘗試了很多選擇:)... – merlachandra

回答

0

的評論,

...如果是Nibus的外觀和感覺,然後我需要改變的外觀和感覺我的代碼...

你需要的東西這一點,

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

也看看這個:How to Set the Look and Feel