This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Jlabels Automatically depending on Database values  RSS feed

 
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: 2756
12
  • 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: 2504
27
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!