データは動的なので、GUIも動的でなければなりません。
は、次の例を考えてみましょう:あなたは、あなたがする必要がある結果セットを解析している場合
import javax.swing.JLabel;
import javax.swing.JRadioButton;
public class GuiRow {
/** jRadioButton */
private JRadioButton jRadioButton;
/** studentIdLabel */
private JLabel studentIdLabel;
/** nameLabel */
private JLabel nameLabel;
/** courseLabel */
private JLabel courseLabel;
/**
* Constructs a new instance.
*
* @param studentIdtext
* @param nameText
* @param courseText
*/
public GuiRow(String studentIdtext, String nameText, String courseText) {
this.setjRadioButton(new JRadioButton(""));
// TODO configure radio button
this.setStudentIdLabel(new JLabel(studentIdtext));
this.setNameLabel(new JLabel(nameText));
this.setCourseLabel(new JLabel(nameText));
}
/**
* Get jRadioButton.
*
* @return jRadioButton
*/
public JRadioButton getjRadioButton() {
return this.jRadioButton;
}
/**
* Set jRadioButton.
*
* @param jRadioButton
*/
public void setjRadioButton(JRadioButton jRadioButton) {
this.jRadioButton = jRadioButton;
}
/**
* Get studentIdLabel.
*
* @return studentIdLabel
*/
public JLabel getStudentIdLabel() {
return this.studentIdLabel;
}
/**
* Set studentIdLabel.
*
* @param studentIdLabel
*/
public void setStudentIdLabel(JLabel studentIdLabel) {
this.studentIdLabel = studentIdLabel;
}
/**
* Get nameLabel.
*
* @return nameLabel
*/
public JLabel getNameLabel() {
return this.nameLabel;
}
/**
* Set nameLabel.
*
* @param nameLabel
*/
public void setNameLabel(JLabel nameLabel) {
this.nameLabel = nameLabel;
}
/**
* Get courseLabel.
*
* @return courseLabel
*/
public JLabel getCourseLabel() {
return this.courseLabel;
}
/**
* Set courseLabel.
*
* @param courseLabel
*/
public void setCourseLabel(JLabel courseLabel) {
this.courseLabel = courseLabel;
}
}
これはあなたのコンテナ内の行を作成し、整理するための簡単なオブジェクト(?おそらくJPanelの、右)
ですそのようなオブジェクトのリストを作成し、そこにデータを追加します。ここで
は、あなたが2つの以上のメソッドに分割し、適切なエンティティに置くことができ、データを、解析し、表示する方法についての簡単な例です:
int resultsetSize = resultset.getFetchSize();
//init the list
List<GuiRow> guiRowList = new ArrayList<GuiRow>(resultsetSize);
while (resultset.next()) {
//get the column values
String id = resultset.getString("studentId");
String name = resultset.getString("studentName");
String course = resultset.getString("course");
//create the the entry
GuiRow guiRow = new GuiRow(id, name, course);
//add it to the list
guiRowList.add(guiRow);
}
//now that you have a nice list of rows add them one by one to the container
JPanel container = new JPanel(new GridLayout(resultsetSize, 4));
//further container configuration could be done here ...
for (GuiRow row : guiRowList) {
container.add(row.getjRadioButton());
container.add(row.getStudentIdLabel());
container.add(row.getNameLabel());
container.add(row.getCourseLabel());
}
それはあなたがあなたの質問のタイトルで言っただけのようです。 'JRadioButton'への参照が' btn'であると仮定すると、単に 'btn.setText(s1)'を呼び出します。 'JLabel'はパブリック' setText'メソッドを持ち、 'JRadioButton'は' AbstractButton'からそれを継承します。 – ccjmne
あなたの提案に感謝しますが、2つ以上のレコードがフェッチされているので、別のJRadioButtonとJLabelに表示したいので、変数名が異なっています。例レコードが2つ取り出されているので、 BT2など詳細は添付のスクリーンショットをご覧ください –