2015-02-07 219 views
1
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.pngJTextArea中具有相同的參數,但不相同的尺寸

可以看到的「sousclass」面板比其他的JTextArea用同樣的參數更小的文本區域(8 ,19)。有誰能告訴我爲什麼?

此外,假設我有一些數據,我想在課堂部分顯示班級名稱,一旦我點擊其中一個班,它顯示attribut部分該班的attributs,我怎麼能實現這個功能?謝謝。

回答

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 

你沒有設置文本區域的空白。您正在使用錯誤的變量名稱。

+0

對,這樣簡單的錯誤....非常感謝。你對我的第二個問題有答案嗎? – BroLegend 2015-02-08 05:48:05

相關問題