JTable: Resizable Row Header

Hi,
Did anyone implement a row header class for JTable that allows to resize rows (the height of rows) like JTableHeader does for columns?

Take a look at the link shown below:
http://forum.java.sun.com/thread.jsp?forum=57&thread=252175
;o)
V.V.

Similar Messages

  • Resizing row header of jtable

    hi,
    Is there any way to resize row header column of a jtable just as other columns of jtable. i searched in forums and google but couldnt find any article with resizing row header.
    thanx

    If you want help in the future I suggest you remain a little more patient. It's the weekend. People don't hang around waiting for you to post a question. We answer questions if and when we have time and we know the answer.
    The general answer is yes, of course, it can be done. But we can't give you a specifice answer since you question is so general.
    For example, take a look at my code in this posting:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=639189
    I made the following changes:
    //          addColumn( new TableColumn() );
              TableColumn column = new TableColumn();
              column.setHeaderValue(" ");
              addColumn( column );And then I overrode the following method of the table:
    public void columnMarginChanged(ChangeEvent e)
         super.columnMarginChanged(e);
         TableColumn resizingColumn = getTableHeader().getResizingColumn();
         if (resizingColumn != null)
              Dimension d = getPreferredSize();
              d.width = resizingColumn.getWidth();
              setPreferredScrollableViewportSize(d);
    }and finally
    scrollPane.setRowHeaderView( lineTable );
    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, lineTable.getTableHeader()); // newOf course we have no idea what component you are using for your row header so we can't give a detailed solution, but I suspect you would need to do something like the following:
    a) add a mouseListener to your component
    b) calculate the change in size of the component using the mouse location changes
    c) set the preferred size of your component
    d) notify the scroll pane of the change in size. I would look at the setPreferredScrollableViewportSize method of JTable to see what it does.

  • JTable with row header plus value extraction from headers

    Hi, I am trying to do the following:
    Short Version-
    1. Create a table that has both row and column headers
    2. Allow the user to mouse over any of these headers such that doing so will display an image I have produced on a panel. (I already know how to create the image and how to display it, I'm just not sure how to associate it with a particular row or column header)
    3. Make the row headers look as much as possible like the column headers.
    Slightly Longer Version-
    Column headers will be labled A-H (maximum) while row headers will be labled 1-12 (maximum). Either can be less, however, depending on user input. After the table has been realized, the user will move the mouse over say, header 'H' and when they do, a JPEG image will appear on another panel and a tooltip will appear above the cell showing a formula. This happens when either row or column headers are moused over.
    Currently, I am using the following code from the O'reilly Swing book as a baseline for experimentation but any help you can offer will be appreciated. I'm fairly new to the JTable world... :-(
    TableModel tm = new AbstractTableModel(){
                   String data[] = {"", "a", "b", "c", "d", "e"};
                   String headers [] = {"Row #", "Column1", "Column2", "Column3", "Column4", "Column5"};
                   public int getColumnCount(){ return data.length;}
                   public int getRowCount() { return 1000;}
                   public String getColumnName(int col){ return headers[col];}
                   public Object getValueAt(int row, int col){
                        return data[col] + row;
              //creates a column model for the main table. This model ignores the first
              //column added and sets a minimum width of 150 pixels for all others
              TableColumnModel cm = new DefaultTableColumnModel(){
                   boolean first = true;
                   public void addColumn(TableColumn tc){
                        if(first) {first = false; return;}
                        tc.setMinWidth(150);
                        super.addColumn(tc);
              //Creates a column model that will serve as the row header table. This model
              //picks a maxium width and stores only the first column
              TableColumnModel rowHeaderModel = new DefaultTableColumnModel(){
                   boolean first = true;
                   public void addColumn(TableColumn tc){
                        if(first) {
                             tc.setMaxWidth(tc.getPreferredWidth());
                             super.addColumn(tc);
                             first = false;
              JTable grid = new JTable(tm, cm);
              //set up the header column and hook it up to everything
              JTable headerColumn = new JTable(tm, rowHeaderModel);
              grid.createDefaultColumnsFromModel();
              headerColumn.createDefaultColumnsFromModel();
              //make sure the selection between the main table and the header stay in sync
              grid.setSelectionModel(headerColumn.getSelectionModel());
              headerColumn.setBorder(BorderFactory.createEtchedBorder());
              headerColumn.setBackground(Color.lightGray);
              headerColumn.setColumnSelectionAllowed(false);
              headerColumn.setCellSelectionEnabled(false);
              JViewport jv = new JViewport();
              jv.setView(headerColumn);
              jv.setPreferredSize(headerColumn.getMaximumSize());
              //to make the table scroll properly
              grid.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
              //have to manually attach row headers but after that, the scroll pane
              //keeps them in sync
              JScrollPane jsp = new JScrollPane(grid);
              jsp.setRowHeader(jv);
              jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader());
              gridPanel.add(jsp, BorderLayout.NORTH);

    There a number of nice examples on JTable: http://www.senun.com/Left/Programming/Java_old/Examples_swing/SwingExamples.html
    Hope you could find something suitable ...
    Regards,
    Anton.

  • JTable - Resize rows the same way as the columns

    Hi!
    I have run into a very frustrating problem and have tried to solve this for many hours but can't come up with a good solution. If there is anyone that can help me on the right track I will be very grateful!
    When I'm using a JTable it provides good "graphical" functionality to handle resize of colums, but when it comes to resize rows it is not available.
    I have found a solution for the row height adjustment in the following post: [http://forums.sun.com/thread.jspa?forumID=257&threadID=453665]
    That solution only partially work in my case because of the following:
    The JTable exists inside a JInternalFrame and the JTable should not be able to get bigger then the actual size of the InternalFrame it is put in (so no scrollbar).
    The problem with the solution above is that the JTable total height will also expand when a row is resized (contrary to what happens when the columns are resized), ending up with a JTable that is bigger then the InternalFrame.
    So my question is:
    Is it possible to provide the same ("graphical") resize functionality for rows as for columns in a JTable? Or any row resize functionality that prevent the JTable from getting bigger then the container it is placed in?
    Thanks for your time!
    Best regards,
    Marcus

    Thanks for the fast answer!
    Yes, that would solve the height expanding problem. Thanks!
    It would be even better though if the row resize functionality would behave the same as the column resize (for consistency). For example: If a row is resized the other rows will get smaller so they all fit into the InternalFrame.
    It has to be some easy way to do this. I have started on a solution with component listeners etc. (to track resize) but it is quite hard to get it right and I keep getting the feeling I reinventing the wheel all over again:(
    Any ideas out there?

  • Resize Row in a JTable??

    Hi,
    Is it possible to allow the 'user' to resize the height of a row in JTable??
    I know that we can programatically set the height of a row through setRowHeight method.
    But my requirement is to allow the 'user' to resize the height of a row. If resized, how can I get the new height of the row??
    Regards,
    Satish

    Very interesting and difficult question.
    I think the best way is to create a row header (like in excel) which allows to resize the rows individually.
    I will work on this problem.
    Denis

  • How to make the row header of the JTable respond to mouse events?

    Is there an easy way to enable the row header of a JTable so it listens to mouse events? I have put a button in the first cell of the row header but I can't click in it.
    I'm asking for an easy way because I've seen some fairly complicated examples on the web that seem close to what I want but I was hoping something simple like getRowHeader().setEnabled(true) would do the trick for my case...

    What's your row header, another JTable or something else? Check out camickr's [url http://tips4java.wordpress.com/2009/07/12/table-button-column/]Table Button Column.
    db
    edit Or to get better help sooner, post a [url http://mindprod.com/jgloss/sscce.html]SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
    Edited by: Darryl Burke

  • Error in JTable Row Header

    in my program i am displaying a row header in my JTable it is displaying no problem in these the real problem is that the row header extends to the end of the frame .. is that happen or i made any mistake
    here is my code
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class RowHeaderExample1    extends JFrame
    JTable table;
    public RowHeaderExample1()
    super("Row Header Example1"); 
      setSize(300, 150);
        ListModel listModel = new AbstractListModel()
      String headers[] =
    "Row 1", "Row 2", "Row 3", "Row 4", "Row 5", "Row 6"}; 
        public int getSize()
    return headers.length;   
      public Object getElementAt(int index)
    {        return headers[index];  
    DefaultTableModel defaultModel = new DefaultTableModel(listModel.getSize(),        10); 
      table = new JTable(defaultModel);  
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 
      // Create single component to add to scrollpane 
      final JList rowHeader = new JList(listModel);  
    rowHeader.setFixedCellWidth(40);  
    rowHeader.setFixedCellHeight(table.getRowHeight());  
    rowHeader.setCellRenderer(new RowHeaderRenderer1(table)); 
      JScrollPane scroll = new JScrollPane(table); 
      scroll.setRowHeaderView(rowHeader);   
    // Adds row-list left of the table 
      getContentPane().add(scroll, BorderLayout.CENTER); 
      rowHeader.addMouseListener(new MouseAdapter()
      public void mouseClicked(MouseEvent e) {   
        System.out.println("click Here 1");   
        int index = rowHeader.locationToIndex(e.getPoint());  
         table.setRowSelectionInterval(index, index);   
        table.requestFocus();   
      public static void main(String[] args)
    RowHeaderExample1 frame = new RowHeaderExample1();   
    frame.addWindowListener(new WindowAdapter()
       public void windowClosing(WindowEvent e)
    {        System.exit(0);    
      frame.setVisible(true);
    class RowHeaderRenderer1 extends JButton implements ListCellRenderer{ 
      JTable table; 
      public RowHeaderRenderer1(JTable table)
    this.table = table; 
        setFont(new Font("Dialog",0,11));   
      setMargin(new Insets(0,0,0,0));  
    public Component getListCellRendererComponent(JList list, Object value,int index, boolean isSelected, boolean hasFocus)
    list.setBackground(getBackground());  
       this.setText(value.toString());   
      return this;   
    public Component getListCellRendererComponent(JList list, Object value, boolean isSelected, boolean hasFocus){   
    list.setBackground(getBackground());    
    this.setText(value.toString());   
      return this; 
    }}

    try this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class RowHeaderExample2
        extends JFrame {
      JTable table;
      DefaultListModel lstModel;
      DefaultTableModel defaultModel;
      public RowHeaderExample2() {
        super("Row Header Example");
        setSize(300, 150);
        lstModel = new DefaultListModel();
        lstModel.addElement("Row 1");
        lstModel.addElement("Row 2");
        lstModel.addElement("Row 3");
        lstModel.addElement("Row 4");
        defaultModel = new DefaultTableModel(lstModel.getSize(), 6);
        table = new JTable(defaultModel);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        // Create single component to add to scrollpane
        final JList rowHeader = new JList(lstModel);
        rowHeader.setFixedCellWidth(40);
        rowHeader.setFixedCellHeight(table.getRowHeight());
        rowHeader.setCellRenderer(new RowHeaderRenderer2(table));
        JButton btnAdd = new JButton("Add");
        btnAdd.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
            lstModel.addElement("Row "+lstModel.getSize()+1);
            defaultModel.addRow(new Object[]{"","","","","",""});
        JPanel panel = new JPanel();
        panel.add(btnAdd);
        JScrollPane scroll = new JScrollPane(table);
        scroll.setRowHeaderView(rowHeader); // Adds row-list left of the table
        getContentPane().add(panel, BorderLayout.NORTH);
        getContentPane().add(scroll, BorderLayout.CENTER);
        rowHeader.addMouseListener(new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            System.out.println("click Here 1");
            int index = rowHeader.locationToIndex(e.getPoint());
            table.setRowSelectionInterval(index, index);
            table.requestFocus();
      public static void main(String[] args) {
        RowHeaderExample2 frame = new RowHeaderExample2();
        frame.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
        frame.setVisible(true);
    * Define the look/content for a cell in the row header
    * In this instance uses the JTables header properties
    class RowHeaderRenderer2
        extends JLabel
        implements ListCellRenderer {
       * Constructor creates all cells the same
       * To change look for individual cells put code in
       * getListCellRendererComponent method
      JTable table;
      RowHeaderRenderer2(JTable table) {
        this.table = table;
        JTableHeader header = table.getTableHeader();
        setOpaque(true);
        setBorder(UIManager.getBorder("TableHeader.cellBorder"));
        setHorizontalAlignment(CENTER);
        setForeground(header.getForeground());
        setBackground(header.getBackground());
        setFont(header.getFont());
       * Returns the JLabel after setting the text of the cell
      public Component getListCellRendererComponent(JList list,
                                                    Object value, int index,
                                                    boolean isSelected,
                                                    boolean cellHasFocus) {
        list.setBackground(table.getTableHeader().getBackground());
        setText( (value == null) ? "" : value.toString());
        return this;
    }

  • JTable with Multiple Row Header

    well, Im do an application thats need formated ISOS Sheets, and most of them have a Table with Multiple Row Header , and Groupable Header, and both of them. I have the .java and in the class MultipleRowHeaderExample calls a class AttributiveCellTableModel for setColumnIdentifiers() and setDataVector() the cue is why this print stack :
    Exception in thread "main" java.lang.StackOverflowError
         at java.util.Vector.<init>(Unknown Source)
         at java.util.Vector.<init>(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:54)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
    .if in main class, have initialized the data, and column vars
    public class MultipleRowHeaderExample extends JFrame {
      Object[][] data;
      Object[] column;
      JTable table;
      MultiSpanCellTable fixedTable;
      public MultipleRowHeaderExample() {
        super( "Multiple Row Header Example" );
        setSize( 400, 150 );
        data =  new Object[][]{
            {"SNo."    ,"" },
            {"Name"    ,"1"},
            {""        ,"2"},
            {"Language","1"},
            {""        ,"2"},
            {""        ,"3"}};
        column = new Object[]{"",""};
        AttributiveCellTableModel fixedModel = new AttributiveCellTableModel(data, column) {
          public boolean CellEditable(int row, int col) {
            return false;
        };

    What's the code in AttributiveCellTableModel?
    * (swing1.1beta3)
    package jp.gr.java_conf.tame.swing.table;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    * @version 1.0 11/22/98
    public class AttributiveCellTableModel extends DefaultTableModel {
      protected CellAttribute cellAtt;
      public AttributiveCellTableModel() {
        this((Vector)null, 0);
      public AttributiveCellTableModel(int numRows, int numColumns) {
        Vector names = new Vector(numColumns);
        names.setSize(numColumns);
        setColumnIdentifiers(names);
        dataVector = new Vector();
        setNumRows(numRows);
        cellAtt = new DefaultCellAttribute(numRows,numColumns);
      public AttributiveCellTableModel(Vector columnNames, int numRows) {
        setColumnIdentifiers(columnNames);
        dataVector = new Vector();
        setNumRows(numRows);
        cellAtt = new DefaultCellAttribute(numRows,columnNames.size());
      public AttributiveCellTableModel(Object[] columnNames, int numRows) {
        this(convertToVector(columnNames), numRows);
      public AttributiveCellTableModel(Vector data, Vector columnNames) {
        setDataVector(data, columnNames);
      public AttributiveCellTableModel(Object[][] data, Object[] columnNames) {
        setDataVector(data, columnNames);
      public void setDataVector(Vector newData, Vector columnNames) {
        if (newData == null)
          throw new IllegalArgumentException("setDataVector() - Null parameter");
        dataVector = new Vector();
        setColumnIdentifiers(columnNames);
        dataVector = newData;
        cellAtt = new DefaultCellAttribute(dataVector.size(),
                                           columnIdentifiers.size());
        newRowsAdded(new TableModelEvent(this, 0, getRowCount()-1,
               TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
      @Override
      public void setColumnIdentifiers(Vector arg0) {
              // TODO Auto-generated method stub
              super.setColumnIdentifiers(arg0);
      public void addColumn(Object columnName, Vector columnData) {
        if (columnName == null)
          throw new IllegalArgumentException("addColumn() - null parameter");
        columnIdentifiers.addElement(columnName);
        int index = 0;
        Enumeration enumeration = dataVector.elements();
        while (enumeration.hasMoreElements()) {
          Object value;
          if ((columnData != null) && (index < columnData.size()))
           value = columnData.elementAt(index);
          else
         value = null;
          ((Vector)enumeration.nextElement()).addElement(value);
          index++;
        cellAtt.addColumn();
        fireTableStructureChanged();
      public void addRow(Vector rowData) {
        Vector newData = null;
        if (rowData == null) {
          newData = new Vector(getColumnCount());
        else {
          rowData.setSize(getColumnCount());
        dataVector.addElement(newData);
        cellAtt.addRow();
        newRowsAdded(new TableModelEvent(this, getRowCount()-1, getRowCount()-1,
           TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
      public void insertRow(int row, Vector rowData) {
        if (rowData == null) {
          rowData = new Vector(getColumnCount());
        else {
          rowData.setSize(getColumnCount());
        dataVector.insertElementAt(rowData, row);
        cellAtt.insertRow(row);
        newRowsAdded(new TableModelEvent(this, row, row,
           TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
      public CellAttribute getCellAttribute() {
        return cellAtt;
      public void setCellAttribute(CellAttribute newCellAtt) {
        int numColumns = getColumnCount();
        int numRows    = getRowCount();
        if ((newCellAtt.getSize().width  != numColumns) ||
            (newCellAtt.getSize().height != numRows)) {
          newCellAtt.setSize(new Dimension(numRows, numColumns));
        cellAtt = newCellAtt;
        fireTableDataChanged();
      public void changeCellAttribute(int row, int column, Object command) {
        cellAtt.changeAttribute(row, column, command);
      public void changeCellAttribute(int[] rows, int[] columns, Object command) {
        cellAtt.changeAttribute(rows, columns, command);
    }that's it

  • Word wrapping in row header cell in OLAPDataGrid

    I have an issue with the OLAPDatagrid. Does anyone know how
    to wrap text in the row header cells?
    (to avoid confusion, i will demonstrate my issue using a grid
    with 1 row and 1 column dimension).
    OLAPDataGrid has 2 properties: wordWrap, which only seems to
    affect the data cells, and headerWordWrap which only appears to
    affect the dimension data across the topmost row.
    However, neither of these properties appear to allow the row
    dimensions' data to wrap (this is the data in the leftmost column).
    Not only this, the column does not automatically resize to reveal
    the data.
    I also can't see how to manually modify the width of the
    columns as at the point when the olapdatagrid's dataprovider is
    assigned to the olapresult, the column count is zero.
    any suggestions?
    thanks
    Mark

    //i tryied this it is not working
    //its selecting the first colum first row and when i clicked the second row header it is selecting the second //column seconf row.
    //And pressing Ctrl [key] and click row header is not working.
    what do u mean by Second row header. For a Table we wil be having only one header na

  • Displaying jtable as rows instead of columns

    This may be really simple, but I can't figure it out. I want to display information in a JTable as rows instead of columns. Can anyone help me with this?
    Thanks in advance,
    m

    Check here:
    http://www2.gol.com/users/tame/swing/examples/SwingExam
    les.html
    They may well have what you want, if not they will
    probably have some ideas you can use.There's always the swing tutorial, also. I learned JTables from the tutorial at http://java.sun.com/docs/books/tutorial/uiswing/components/table.html and it gave me a lot of good ideas and points to start from.
    You could probably create your own cell renderer (or use the header renderer) and set the first column to use that to display their text.

  • Print JTable with row headers

    I am using the fancy new printing capablities in java 1.5 to print my JTable and wow is it ever slick!
    PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
    set.add(OrientationRequested.LANDSCAPE);
    this.matrixJTable.print(JTable.PrintMode.NORMAL, null, null, true, set, false);Its just that easy. Way to go sun!
    The one problem that I am encountering is that my row headers don't print. The problem is that JTables don't support row headers, you have to use a JScrollPane for that.
    I need a way to print my JTable so that the row headers show up in the printout... and hopefully still use the warm and fuzzy new printing capabilities of JTable printing in java 1.5.
    (ps/ Isn't it time to add row header support to JTables?)

    The problem is that JTables don't support row headers, you have to use a JScrollPane for that.Well technically JTable's don't really support column headers either. It is a seperate component (JTableHeader). A JTable will automatically add its table header to the table header area of a JScrollPane. (but you don't have to use a jscrollpane to see the column headers, it is just the quickest and easiest way).
    Really shouldn't be hard to implement a row header and manually add it to the scroll panes row header area or use a BorderLayout and put your row header in the WEST and put your table in the CENTER if you don't want a scroll pane.
    Of course this won't help you with your printing issue.

  • Adiing row header to J Table

    i want to add my row header dynamically when i am add a row by pressing the add button it is possible..
    and thr problem iam facing in this program is that the row header is there but along with row header a label like shade visible upto the end of frame.
    Any help over these
    And this is my code
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    ]import javax.swing.table.*;
    public class RowHeaderExample extends JFrame {JTable table;  
    public RowHeaderExample()
    {        super( "Row Header Example" );    
       setSize( 300, 150 );    
       ListModel listModel = new AbstractListModel() {   
            String headers[] = {"","","","","","" };        
       public int getSize() { return headers.length; }    
           public Object getElementAt(int index) { return headers[index];
         DefaultTableModel defaultModel =            new DefaultTableModel(listModel.getSize(),10);  
          table = new JTable( defaultModel );   
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);    
       // Create single component to add to scrollpane  
    final JList rowHeader = new JList(listModel);    
       rowHeader.setFixedCellWidth(40);    
       rowHeader.setFixedCellHeight(table.getRowHeight());      
    rowHeader.setCellRenderer(new RowHeaderRenderer(table));   
        JScrollPane scroll = new JScrollPane( table ); 
          scroll.setRowHeaderView(rowHeader);
    // Adds row-list left of the table      
    getContentPane().add(scroll, BorderLayout.CENTER);   
       rowHeader.addMouseListener(new MouseAdapter() {     
         public void mouseClicked(MouseEvent e) {     
         System.out.println("click Here 1");          
    int index = rowHeader.locationToIndex(e.getPoint());
    table.setRowSelectionInterval(index,index);          
    table.requestFocus();     
    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); 

    actually i dont quite understand your problem, dont know whether this one solve your problem, i guess may be the problem come from your renderer
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class RowHeaderExample
        extends JFrame {
      JTable table;
      public RowHeaderExample() {
        super("Row Header Example");
        setSize(300, 150);
        ListModel listModel = new AbstractListModel() {
          String headers[] = {
              "Row 1", "Row 2", "Row 3", "Row 4", "Row 5", "Row 6"};
          public int getSize() {
            return headers.length;
          public Object getElementAt(int index) {
            return headers[index];
        DefaultTableModel defaultModel = new DefaultTableModel(listModel.getSize(),
            10);
        table = new JTable(defaultModel);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        // Create single component to add to scrollpane
        final JList rowHeader = new JList(listModel);
        rowHeader.setFixedCellWidth(40);
        rowHeader.setFixedCellHeight(table.getRowHeight());
        rowHeader.setCellRenderer(new RowHeaderRenderer(table));
        JScrollPane scroll = new JScrollPane(table);
        scroll.setRowHeaderView(rowHeader);
        // Adds row-list left of the table
        getContentPane().add(scroll, BorderLayout.CENTER);
        rowHeader.addMouseListener(new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            System.out.println("click Here 1");
            int index = rowHeader.locationToIndex(e.getPoint());
            table.setRowSelectionInterval(index, index);
            table.requestFocus();
      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);
      class RowHeaderRenderer extends JButton implements ListCellRenderer{
        JTable table;
        public RowHeaderRenderer(JTable table){
          this.table = table;
          setFont(new Font("Dialog",0,11));
          setMargin(new Insets(0,0,0,0));
        public Component getListCellRendererComponent(JList list, Object value,int index, boolean isSelected, boolean hasFocus){
          list.setBackground(getBackground());
          this.setText(value.toString());
          return this;
        public Component getListCellRendererComponent(JList list, Object value, boolean isSelected, boolean hasFocus){
          list.setBackground(getBackground());
          this.setText(value.toString());
          return this;
    }

  • Print a JTable with several Header and Footers

    Hi everybody,
    my name is Lothar and I come from Germany. My english is not very well, but I hope you understand me an my problem.
    I want to print a JTable, but I want to print a header with several headers and footers.
    For example:
    h3. Header
    h5. 1. Subtitle
    h5. 2. Subtitle
    Table
    h5. 3. Subtitle
    h5. Footer
    But, I do not know how I can do that. Can anybody tell me, how I can solve my problem. Please, explain for a newbie because I have learned Java since two months ;)
    Here the code:
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import java.util.Date;
    import javax.swing.*;
    public class Beispiel extends JFrame implements ActionListener {
        private JTable table;
        public static void main(String[] args) {
            Beispiel tl = new Beispiel();
            tl.setVisible(true);
            tl.pack();
        public Beispiel() {
            setLayout(new BorderLayout());
            // DruckButton
            JButton print = new JButton("Print");
            add(print, BorderLayout.SOUTH);
            print.addActionListener(this);
            // Tabelle
            add(new JScrollPane(createTable()), BorderLayout.CENTER);
            // schlie&szlig;t das Frame
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public JTable createTable() {
            // titel
            String[] title = new String[] { "Datum", "Von", "Bis",
                    "Dauerinsgesamt", "Bemerkung" };
            // daten
            String[][] data = new String[][] { { "", "", "", "", "" },
            table = new JTable(data, title);
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            return table;
        public void actionPerformed(ActionEvent e1) {
            MessageFormat header = new MessageFormat("Header");
            MessageFormat footer = new MessageFormat("Footer");
            try {
                table.print(JTable.PrintMode.FIT_WIDTH, header, footer);
            } catch (Exception e2) {
                System.err.format("Cannot print %s%n", e2.getMessage());
    }

    Nobody?
    Can nobody solve my problem?

  • SSRS Table/Row Header does not repeat on every page when exported to PDF

    Hi, I have a SSRS Report in which the rows are grouped and the Tablix has a Table/Row header. I wanted the header to repeat on every page for a group because sometimes the data from the group would be more than one page.
                                   To achieve this
                                   - I went to Advance mode by clicking the arrow next to column group
                                   - Selected the Header Static column from Row Group
                                   - Changed the following properties
                                                    - KeepWithGroup: After
                                                    - RepeatOnNewPage:
    True
                                                    - The header columns
    are set to not grow.
    The problem only occurs when the nested grouped data in one of the columns goes over a page. The following pages don't have any header.
    So half of the time the header row repeats but when the nested grouped data extends over one page the header does not show. Problem only occurs when rendered to pdf.
    I found this line "Headings are repeated on each page only if there is sufficient room" in SQL 2008 version. But I could not find it in later versions of sql server. So does that mean it is fixed

    Hi Mumblesnz1,
    According to your description, you specify value of RepeatOnNewPage as True in the report. When exporting the report to PDF, one grouped data extend over one page, and tablix header display on first page, not repeat on following pages.
    As we tested in our environment(SQL Server 2008(SP3)-10.0.5520.0(X64)), it works as you required. We set KeepWithGroup as After and RepeatOnNewPage as True. After exporting to PDF, the grouped data display on two pages, and tablix header repeats on each
    page. Since we haven’t found any document mentioned this issue is fixed on which version, I suggest you try to install the service pack 3 for sql server 2008.
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu

  • How to repeat row header in all pages in Financial Reporting?

    Hi,
    I have created a simple Financial Report with landscape mode, I could not able to view the row header in second page. Please help me out , how to repeat row header in all pages?
    Edited by: Awesome on Dec 13, 2012 2:04 PM

    Hi,
    Refer following link which states how to change the Page Setup setting (just an addition to above poster's explanation):-
    http://docs.oracle.com/cd/E12825_01/epm.111/fr_user/frameset.htm?1900.html
    Regards,
    Edited by: 918547 on Dec 14, 2012 6:17 PM

Maybe you are looking for