tags:

views:

206

answers:

2

i would like to display the records retrieved after a query in the following format

'Record 1 of 20'

I have the rownum and the total records retrieved. It is just the displaying that i need to know. It will be great if it could be displayed in a JLabel.

thanks

A: 
label.setText("Record "+i+" of "+rownum);

Note that you must process events for the value to be displayed, so when you simply set the text and then continue processing (blocking the main thread), the value will be in the widget but the OS won't be able to render it on the screen.

Aaron Digulla
Please wrap it in SwingUtilities.invokeLater() to be sure.
kd304
That will also fail if you block the main thread.
Aaron Digulla
If he is doing the query in EDT then yes. If he does it in a separate thread, then the invokeLater() is a safe way to avoid threading problems.
kd304
Thank you for your feedback
A: 

I like using String.format:

label.setText(String.format("Record %d of %d", rownum, total));
dfa
Thank you. It was helpful.