• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

little boxes in my JTable

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am getting little boxes in my JTable:


I believe this is because I am filling the rows with an array of objects, and for values beginning with numerics, these are being incorrectly rendered. Has anyone seen this, or know a good way around?
Thanks!
Skip
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use trim function before copying to array of object.
joey
 
Skip Cole
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for the information. I should have explained the problem more:
I would use the trim function, but these Strings come staight out of the database as an array of Strings. I then put them into a vector of vectors (one vector for each row representing each flight), and then pass them as a serialized object to the client. This vector of vectors feeds right into the JTable. To do 'trim' on each String I either have to modify the database, or unbundle everything, trim them, and then package them up again to feed to the JTable.
I was hoping to use something like a modified TableRender to clean this up. I guess I could put them in a loop and trim them at some point. I just hoped there was a better way. Also, I want to learn more about how to use the JTable.
Thanks for the response,
Skip
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Skip,
Are you using "setModel" to feed the data into your JTable? I implemented a class that extends AbstractTableModel, and when I use setModel, it wipes out the headers. I too am having the problem with the squares...
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi skip & Douglas,
I have got the solution for this problem. In your JTable's tablemodel At getValueAt(int row, int col), before returning value, you have to trim the value. That's the exact position for placing trim() method.

code:
public Object getValueAt(int row, int col)
{
return (Object)(records[row][col].trim());
}
I think it will help you
mail me to anilkumar_java@rediffmail.com
 
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anil,
Thanks very much--have not tried that yet, but that's the correct way to handle this. My follow-on question was displaying new query results. As I mentioned, I created a descendant of the AbstractTableModel (shown)
public class TableDataInfo extends AbstractTableModel {
String [] columnNames=null;
String [][] data=null;
/**
* This constructor creates a descendant of the AbstractTableModel
* object from the array of DataInfo objects provided in the argument.
*
* @param DataInfo[] - DataInfo array.
*/
TableDataInfo (DataInfo [] inputDataInfo) {
FieldInfo [] TFieldInfo = inputDataInfo[0].getFields();
String [] vals = new String [TFieldInfo.length];
columnNames = new String [TFieldInfo.length];
data = new String [inputDataInfo.length][inputDataInfo[0].getValues().length];
/*
* load columnNames
*/
for (int i=0; i < TFieldInfo.length; i++) {
columnNames[i] = new String (TFieldInfo[i].getName());
}
/*
* load data
*/
for (int i=0; i < inputDataInfo.length; i++) {
vals = inputDataInfo[i].getValues();
for (int j=0; j < vals.length; j++) {
data[i][j] = new String (vals[j]);
}
}
}
HOWEVER, WHEN DISPLAYING THE RESULTS, THIS WIPES OUT THE HEADERS. DO YOU HAVE ANY IDEAS ON THIS?
THANKS MUCH,
DOUG
 
Skip Cole
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My headers were wiped out until I put it in a JScrollPane. Maybe this will help.
Thanks for your help guys! Now I got rid of my little boxes :-)
Skip
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know why the headers on a JTable disappear unless you put the table in a JScrollPane? Is this a bug or a "feature"?
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Dave
I think It is neither a bug nor a feature
But it is starange
But if U need to diplay ur JTable in any container except
JScrollPane, U Need to do the following:
container.setLayout(new BorderLayout());
container.add(table.getTableHeader(), BorderLayout.NORTH);
container.add(table, BorderLayout.CENTER);

The exciting thing about this is that by using above
procedure, U can display ur headers on top or bottom of ur
container.
Hope This Wil Help
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Concerning the trim, I had the same problem. What I did was nab the problem right at the root. The problem is in the readRecord()method in Data class. It constructs a string that is the length of the field, even if the string is smaller. The method it uses is deprecated, so since I had to change it anyway, I just added a trim to it. Now I have a good colection of data.
The problem with putting it in the getValueAt is that you are only affecting the display. Any manipulation you do on the data you will have to remember to trim all the time.
Just a thought
Trevor
 
ramandeep singh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Trevor
I have also done the same thing
I also feel that when we have to modify it any way then
why not to add trim() at that point
 
reply
    Bookmark Topic Watch Topic
  • New Topic