• 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

column margin in JTable

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How can I control the column margin of the header of the table ?
Either use
TableColumnModel.setColumnMargin() or
Jtable.setIntercellSpacing()
the result is same.
When I view The applet in Jre1.3.1 The Column margin is set in the data cells and not in Table Header. Use any value for columnmargin, the header has always margin of 0 and the data cells gets the req. margin.
When I view the same applet in JRe 1.4.1_01 the margin is set both in header and data cells.
So is there any way in jre1.4.1 that can set the header margin as 0 and data margin as 1. or
In jre 1.3.1 How can I set the margin in header also.
Any Solution ?
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also facing the same problem in JRE1.4.1.
Can anyone help us out?
There must be a way to differentiate between setting column margin for only the header and not for the data rows??
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my solution:
I have written a tablecellrenderer that puts an empty border around the rendering component (for example the JLabel for text values). this has the same visual effect as setting the row margin but you are way more flexible. and the row header does not get messed up.
be sure to extend DefaultTableCellRenderer or overwrite the ui updating methods as does this class. (performance reasons, see API)
Chantal
 
Amit Mathur
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response...but I am unable to implement it. We too have a custom CellRenderer but setting a border for it and setting interCellSpacing(0) in JRE1.4.1 does not help!
Can you give a code sample to create empty border for the renderer.
Thanks
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is a sample. you have to set a preferred size for for the table as it computes the size of the cells without counting the border of the label in. so the cells get to small without adding the scrollpane, just by calling pack on the frame with the table.
I hope this is what you need...
Chantal
SAMPLE CODE:
 
Chetan Sharma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks A lot.
I implemented it this way. The Gui Looks Perfect.
But The real problem is that I want to set the Column margin differently for the Header and the table.
A present I followed the following steps.
1. set the column margin to 0
2. myTable.setShowGrid(false);
3. in the cell renderer create a border
But the result is that there is no margin in the cells. The Values to two cells aer very close.
 
Chetan Sharma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chantal for the reply.
earlier I set the bgrid lines to false and used the border like
//this.setBorder(BorderFactory.createMatteBorder(0,0,1,1,Color.gray));
to create the lines between the cells.
So I could not give the margin between the cells.
Now I am using
this.setBorder( BorderFactory.createEmptyBorder( 1, 1, 1, 1 ) );
Now the margin is there between the cells values. But using this technique I encounter I problem. The first two columns are non editable and from the renderer I have set the background color to gray. Now The grid line is not visble between the first two columns. In other words the two cells get merged.
Any solution for this.
Thanks in advance
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Chetan,
I have difficulties to imagine what you're trying to do in your interface.
- why don't you show the table grid if you want to avoid the "merge" of the two cells? (or you could increase the margin (=empty border) to seperate them more clearly)
- if you don't want to use the table grid there is always the possibility to simulate it through the border of the renderer, just as you did before. Borders are not exclusive: you can add as many borders to a component as you like. thus, you can add the empty border to increase the margin and you can add a matte or whatever border to simulate the grid.
did that answer your question?
Chantal
 
Chetan Sharma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to show the grid. My first 2 cols. are disabled and hence background of these 2 cols is gray. When I use empty border then there is no border line between the 1st 2 cols. In the rest of the cols it is Ok.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can change the grid color (JTable API) or the backgound color of the disabled cells.
chantal
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic