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

JTextArea with same parameters but not same size

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

从上面的代码创建的布局是:

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

此外,假设我有一些数据,我想在 class 部分中显示 class 名称,一旦我单击其中一个 class,它会显示 class 的属性属性部分那个class,这个功能怎么实现呢?谢谢。

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

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