【问题标题】:Component alignment on JPanelJPanel 上的组件对齐
【发布时间】:2014-05-06 20:47:35
【问题描述】:

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

这是我的代码。

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


    }

【问题讨论】:

    标签: java swing alignment jpanel


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-05-06
      • 2014-09-17
      • 2014-01-13
      • 2016-08-12
      • 2012-03-14
      • 2021-10-02
      • 2014-07-17
      • 2013-06-10
      • 1970-01-01
      相关资源
      最近更新 更多