2014-03-27 86 views
0

我已經在網上搜索,發現the answer on the this link。我跟着它,但它仍然無法工作。有人會告訴我我錯過了什麼嗎?我的按鈕仍然在面板中央。JPanel上的組件對齊

enter image description here

有我的代碼。

public class PDFJPanel extends JPanel { 



private JPanel jpAnnotation=null; 
private JScrollPane scrollPane = new JScrollPane(); 
private File thisFile=null; 
private PDFNotesBean bean=null; 
private CommentPanel commentPane=null; 

public PDFJPanel (File file) 
{ 
    thisFile=file; 
    getJPanel(); 
} 


public void getJPanel() 

    {      
      this.setLayout(new BorderLayout());   
      this.add(getPDFNotesBean(), BorderLayout.CENTER); 

      commentPane= bean.getCommentPanel();   



      //Right size of the Panel 
      JPanel rightPanel=new JPanel(); 
      rightPanel.setLayout(new BorderLayout());    
      rightPanel.setBackground(Color.GREEN);    

      jpAnnotation=new JPanel();  
       JButton btnUnderline =new JButton(new ImageIcon ("../UnderlineIcon.gif")); 
      btnUnderline.setSize(50, 260); 
      btnUnderline.setAlignmentX(JButton.LEFT_ALIGNMENT); 
      btnUnderline.setHorizontalAlignment(JButton.LEFT); 
      jpAnnotation.add(btnUnderline);  

      rightPanel.add(jpAnnotation, BorderLayout.NORTH); 
      rightPanel.add((Component) commentPane, BorderLayout.CENTER); 
      this.add(rightPanel, BorderLayout.EAST); 


    } 

回答

0

我發現我需要設置這樣的jpAnnotation.setLayout(新的FlowLayout(FlowLayout.LEADING))的佈局;