Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2008

Tip: Looking for answers? Try searching our database.

JTable Row Height Problem

Thread view: 
Edsoncv - 22 Feb 2008 13:58 GMT
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);
 }
Ian Shef - 22 Feb 2008 19:37 GMT
Edsoncv <edsoncv@gmail.com> wrote in news:de85b282-25d9-46fc-b28a-
d8feada5e7ae@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 - 25 Feb 2008 09:53 GMT
> 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...
Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.