JTextArea具有相同的参数但不是相同的大小

时间:2015-02-07 23:11:07

标签: java jpanel jtextarea

public UserInterface(){
    super(new BorderLayout());
    fc = new JFileChooser();
    setComponents();        
}

public void setComponents(){
    //top section
    openButton = new JButton("Charger fichier");
    openButton.addActionListener(this);       
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(openButton);
    //left section
    //class panel
    JPanel classe = new JPanel();
    classes = new JTextArea(25,15);
    classes.setMargin(new Insets(5,5,5,5));
    classes.setEditable(false);
    JScrollPane classeScrollPane = new JScrollPane(classes);
    classe.setBorder(new TitledBorder("Classes"));
    classe.add(classeScrollPane);

    //right section
    JPanel right = new JPanel(new BorderLayout());
    JPanel right_top = new JPanel(new GridLayout(2,2));
    //attribut panel
    JPanel attribut = new JPanel();
    attributs = new JTextArea(8,19);
    attributs.setMargin(new Insets(5,5,5,5));
    attributs.setEditable(false);
    JScrollPane attributScrollPane = new JScrollPane(attributs);
    attribut.setBorder(new TitledBorder("Attributs"));
    attribut.add(attributScrollPane);
    //function panel
    JPanel methode = new JPanel();
    methodes = new JTextArea(8,19);
    methodes.setMargin(new Insets(5,5,5,5));
    methodes.setEditable(false);
    JScrollPane methodeScrollPane = new JScrollPane(methodes);
    methode.setBorder(new TitledBorder("Methodes"));
    methode.add(methodeScrollPane);
    //subclass panel
    JPanel sousclasse = new JPanel();
    sousclasses = new JTextArea(8,19);
    methodes.setMargin(new Insets(5,5,5,5));
    methodes.setEditable(false);
    JScrollPane sousclasseScrollPane = new JScrollPane(sousclasses);
    sousclasse.setBorder(new TitledBorder("Sous-classes"));
    sousclasse.add(sousclasseScrollPane);
    //relation panel
    JPanel relation = new JPanel();
    relations = new JTextArea(8,19);
    relations.setMargin(new Insets(5,5,5,5));
    relations.setEditable(false);
    JScrollPane relationScrollPane = new JScrollPane(relations);
    relation.setBorder(new TitledBorder("Relations"));
    relation.add(relationScrollPane);

    right_top.add(attribut);
    right_top.add(methode);
    right_top.add(sousclasse);
    right_top.add(relation);

    //detail panel
    JPanel detail = new JPanel();
    details = new JTextArea(5,40);
    details.setMargin(new Insets(5,5,5,5));
    details.setEditable(false);
    JScrollPane detailScrollPane = new JScrollPane(details);
    detail.setBorder(new TitledBorder("Détails"));
    detail.add(detailScrollPane);

    right.add(right_top,BorderLayout.CENTER);
    right.add(detail,BorderLayout.SOUTH);

    add(buttonPanel, BorderLayout.NORTH);
    add(classe, BorderLayout.WEST);
    add(right, BorderLayout.CENTER);
}

从上面的代码创建的布局是: http://i.imgur.com/tO7TW90.png

您可以看到' sousclass'的文本区域。 panel小于具有相同参数的其他JTextArea(8,19)。谁能告诉我为什么?

另外,假设我有一些数据,我想在类部分显示类名,一旦我点击其中一个类,它会在attribut部分显示该类的属性,我怎么能实现这个功能谢谢。

1 个答案:

答案 0 :(得分:1)

JPanel sousclasse = new JPanel();
sousclasses = new JTextArea(8,19);
methodes.setMargin(new Insets(5,5,5,5)); // wrong variable
methodes.setEditable(false); // wrong variable

您没有在文字区域设置边距。您使用的是错误的变量名称。