Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JTable Row Height Problem

31 views
Skip to first unread message

Edsoncv

unread,
Apr 27, 2011, 11:43:24 AM4/27/11
to
To: comp.lang.java.gui
I'm having the following problem while configuring a JTable row
height.
The fact is when my row height does not have the exactly heigth of
"row header", exactly figure bellow:

http://www.crionics.com/products/opensource/faq/swing_ex/images/table...

The line height seems almost the same but this little difference
increases as the # of rows increase or the look and feel is changed.

My code is very similar like this:

/* (swing1.1beta3) */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

/**
* @version 1.0 11/09/98
*/

class RowHeaderRenderer extends JLabel implements ListCellRenderer {

RowHeaderRenderer(JTable table) {
JTableHeader header = table.getTableHeader();
setOpaque(true);
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
setHorizontalAlignment(CENTER);
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
}

public Component getListCellRendererComponent( JList list,
Object value, int index, boolean isSelected, boolean
cellHasFocus) {
setText((value == null) ? "" : value.toString());
return this;
}

}

public class RowHeaderExample extends JFrame {

public RowHeaderExample() {
super( "Row Header Example" );
setSize( 300, 150 );

ListModel lm = new AbstractListModel() {
String headers[] = {"a", "b", "c", "d", "e", "f", "g", "h",
"i"};
public int getSize() { return headers.length; }
public Object getElementAt(int index) {
return headers[index];
}
};

DefaultTableModel dm = new DefaultTableModel(lm.getSize(),10);
JTable table = new JTable( dm );
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

JList rowHeader = new JList(lm);
rowHeader.setFixedCellWidth(50);

rowHeader.setFixedCellHeight(table.getRowHeight()
+ table.getRowMargin());
// + table.getIntercellSpacing().height);
rowHeader.setCellRenderer(new RowHeaderRenderer(table));

JScrollPane scroll = new JScrollPane( table );
scroll.setRowHeaderView(rowHeader);
getContentPane().add(scroll, BorderLayout.CENTER);
}

public static void main(String[] args) {
RowHeaderExample frame = new RowHeaderExample();
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
}
});
frame.setVisible(true);
}

---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Ian Shef

unread,
Feb 22, 2008, 2:37:05 PM2/22/08
to
Edsoncv <eds...@gmail.com> wrote in news:de85b282-25d9-46fc-b28a-
d8fead...@e60g2000hsh.googlegroups.com:

> I'm having the following problem while configuring a JTable row
> height.
> The fact is when my row height does not have the exactly heigth of
> "row header", exactly figure bellow:
>
> http://www.crionics.com/products/opensource/faq/swing_ex/images/table...

Result is:

404 Not Found
/products/opensource/faq/swing_ex/images/table was not found on this server.

Maybe I don't understand what "..." is supposed to represent?

Sabine Dinis Blochberger

unread,
Feb 25, 2008, 4:53:39 AM2/25/08
to
Edsoncv wrote:

> I'm having the following problem while configuring a JTable row
> height.
> The fact is when my row height does not have the exactly heigth of
> "row header", exactly figure bellow:
>

<snip>


>
> rowHeader.setFixedCellHeight(table.getRowHeight()
> + table.getRowMargin());
> // + table.getIntercellSpacing().height);
> rowHeader.setCellRenderer(new RowHeaderRenderer(table));
>
>

Since you say the size increases for subsequent rows, maybe you are
adding too many values here multiple times. getRowHeight() might already
include the margin and spacing you added previously...
--
Sabine Dinis Blochberger

Op3racional
www.op3racional.eu

0 new messages