데이터가 동적이기 때문에 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?) 만들고 용기에 행을 구성하는 간단한 객체이다
당신은 당신이 필요로하는 결과 집합을 파싱 그러한 객체들의 목록을 만들고 거기에 데이터를 추가하십시오.
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());
}
그것은 단지 당신이 당신의 질문 제목에서 말했듯이 : 여기
구문 분석하고 해당 기관에서 그들을 2 개 이상의 방법으로 분할하고 배치 할 수있는 데이터를 표시하는 방법에 대한 간단한 예입니다 . 'JRadioButton'에 대한 참조가'btn'이라면 간단히'btn.setText (s1)'을 호출하십시오. 'JLabel'은 public'setText' 메소드를 가지고 있고'JRadioButton'은'AbstractButton'으로부터 그것을 상속받습니다. – ccjmne당신의 제안을 가져 주셔서 감사하지만 이후에 하나 이상의 레코드가 페치 되었기 때문에 별도의 JRadioButton과 JLabel에 표시하고 싶을 때마다 변수 이름이 다를 수 있습니다. 예 레코드가 두 개 있으면 BT1에 데이터가 표시되고 BT2 등 자세한 내용은 첨부 된 스크린 샷을 참조하십시오. –