JPanel上的组件对齐

时间:2014-03-27 17:34:35

标签: java swing alignment jpanel

我在网上搜索过,发现the answer on the this link。我跟着它,但它仍然无法工作。有人会告诉我我错过了什么。我的按钮仍位于面板中央。

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


    }

1 个答案:

答案 0 :(得分:0)

我发现我需要像jpAnnotation.setLayout(new FlowLayout(FlowLayout.LEADING))设置布局;

相关问题