• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Getting Jlabels Automatically depending on Database values

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Rancher
Posts: 3287
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using a load of JLabels?
WOuldn't some form of JTable make more sense?
 
I AM MIGHTY! Especially when I hold this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic