Since the data is dynamic the GUI should be dynamic as well.
Consider the following example:
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;
}
}
This is a simple Object to create and organize a row in your container (probably JPanel, right?)
When you are parsing the resultset you need to build a list of such objects and an add the data in there.
Here is a simple example on how to parse and display the data, which you can split into 2 or more methods and place them in the appropriate entities:
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());
}