2016-08-04 11 views
0

フォームを使って新しいアカウントを追加できるJavaアプリケーションを作成していますが、SpringLayoutはきれいに見えますが、JTextFieldsをそれのテキストは、それはそこに来てはならない一方で、ボタンが左上にとどまり、私はSpringUtilities (https://docs.oracle.com/javase/tutorial/uiswing/examples/layout/SpringGridProject/src/layout/SpringUtilities.javaボタンの位置が奇妙な場所に移動する(SpringLayout)

package dinges.Containers; 

import javax.swing.JButton; 
import javax.swing.JComboBox; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JTextField; 
import javax.swing.SpringLayout; 

import dinges.Utilities.SpringUtilities; 

@SuppressWarnings("serial") 
public class Addnew extends JPanel { 

    String[] options = {"User", "Accountant", "Administrator", "Developer"}; 

    /** 
    * > Add a text input for the following: 
    * > Id, Name, last name, current balance, and the state. But this has to be in order of the new Account. 
    * > we're just going to be using JTextFields, a JButton for saving and JLabels for writing what it is 
    * 
    **/ 

    public Addnew() { 
     // frame size is WIDTH = 280  ,  HEIGHT =  480 
     SpringLayout layout = new SpringLayout(); 
     setLayout(layout); 

     JButton save = new JButton("Save data"); 
     JTextField name = new JTextField(15); 
     JTextField lastname = new JTextField(15); 
     JComboBox<String> accounttype = new JComboBox<String>(options); 
     JLabel label1 = new JLabel("First name: ", JLabel.TRAILING); 
     JLabel label2 = new JLabel("Last name: ", JLabel.TRAILING); 
     JLabel label3 = new JLabel("Account type: ", JLabel.TRAILING); 
     JLabel label4 = new JLabel("Save data: ", JLabel.TRAILING); 
     label1.setLabelFor(name); 
     label2.setLabelFor(lastname); 
     label3.setLabelFor(accounttype); 




     add(label1); 
     add(name); 
     add(label2); 
     add(lastname); 
     add(label3); 
     add(accounttype); 
     add(save); 
     add(label4); 

     SpringUtilities.makeCompactGrid(this, 3, 2, 6, 6, 6, 6); 
    } 

} 

を使用していますこれは、次のようになります:

enter image description here

ボタンはJComboBoxの下にあり、JLabelは他のボタンと同じように配置する必要があります。

問題はどこにありますか?私はしばらくの間、物事を切り換えてきましたが、私は本当にそれを見つけることができません。

答えて

1

ボタンが左上

それがあるべき

のまま?

私はそれが一番下にあるはずだと推測していますが、私たちが読者に気づかず、あなたが何を考えているのか分からないので、質問の一部として指定するべきです。

私はSpringUtilities

を使用していますあなたが必要とするどのように多くの行/列SpringUtilitiesを教えてくれましたか?

デモコードからパラメータを変更したのですか、変更しないでデモコードをコピーしましたか?

+0

の右の数を設定していなかったように私は、私は自分自身と私はただの友達が教えてくれましたどのような春のユーティリティを取ったものをコード化するために使用しています、これに気付かなかったに見えます、私にそれを思い出させてくれてありがとう –

-1

は、あなたが適切に行

// SpringUtilities.makeCompactGrid(p, rows, cols, initX, initY, xPad, yPad); 
    int numPairs = options.length; // 4 
    SpringUtilities.makeCompactGrid(p, numPairs, 2, 6, 6, 6, 6); 
+0

(1-)、はい、1時間前に示唆されました。答えを繰り返す必要はありません。また、「オプション」は行数とは関係ありません。 "options"配列は、コンボボックスで使用されます。 – camickr

関連する問題