• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Jlabels Automatically depending on Database values

 
Muha Hassan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted the same kind of question a few days ago, and got some answers. However. am still not getting the result I want.

am creating a program whereby the user enters Emloyee expenses. Therefore. I want my JLabels  to have the Names of the Employees,

and if the user deletes or adds another employee,  In the EmployeeExpense form, it should have the same.

am using this code per now.

try{
String sql = "select names from Emlpyee";
pst  = conn.preparestatement(sql);
rs= pst.executeQuery();

while(rs.next() ){
Panel1.add(new JLabel(rs.getString("Names")));
}


I don't have any error bt nothing displays either. Please I need answers.

Thanks

 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a component is created it has a default size of (0, 0) so there is nothing to paint.

After the while loop you need to add:


to invoke the layout manager (to give the components a size) and make sure the components are painted.
 
Dave Tolls
Ranch Hand
Posts: 2270
23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using a load of JLabels?
WOuldn't some form of JTable make more sense?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!