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.

Similar Messages

  • 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.

  • 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

  • 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.

  • Select row and column from header in jtable

    hello i have a problem to select row and column from header in jtable..
    can somebody give me an idea on how to write the program on it.

    Hi Vicky Liu,
    Thank you for your reply. I'm sorry for not clear question.
    Answer for your question:
    1. First value of Open is item fiels in Dataset2 and this value only for first month (january). But for other month Open value get from Close in previous month.
    * I have 2 Dataset , Dataset1 is all data for show in my report. Dataset2 is only first Open for first month
    2. the picture for detail of my report
    Detail for Red number:
    1. tb_Open -> tb_Close in previous month but first month from item field in Dataset2
    espression =FormatNumber(Code.GetOpening(Fields!month.Value,First(Fields!open.Value, "Dataset2")))
    2. tb_TOTAL1 group on item_part = 1
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)))
    3. tb_TOTAL2 group on item_part = 3 or item_part = 4
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) + ReportItems!tb_TOTAL1.Value )
    4. tb_TOTAL3 group on item_part = 2
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) - ReportItems!tb_TOTAL2 .Value)
    5. tb_Close -> calculate from tb_TOTAL3 - tb_Open
    expression =FormatNumber(Code.GetClosing(ReportItems!tb_TOTAL3.Value,ReportItems!tb_Open.Value))
    I want to calculate the value of tb_Open and tb_Close. I try to use custom code for calculate them. tb_close is correct but tb_Open is not correct that show value = 0 .
    My custom code:
    Dim Shared prev_close As Double
    Dim Shared now_close As Double
    Dim Shared now_open As Double
    Public Function GetClosing(TOTAL3 as Double,NowOpening as Double)
        now_close = TOTAL3 + NowOpening
        prev_close = now_close
        Return now_close
    End Function
    Public Function GetOpening(Month as String,NowOpen as Double)
        If Month = "1" Then
            now_open = NowOpen
        Else    
            now_open = prev_close
        End If
        Return now_open
    End Function
    Thanks alot for your help!
    Regards
    Panda A

  • 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?

  • 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

  • Resize cells in a JTable.

    I'd like to give some columns, in a jTable, an autoresize mode. It means fitting well with the content (being able to read the longest cell without having to resize the cell manualy by resizing the header).
    Some tables of other applications (like the Excel ones) hava this ability.
    Do S.O. have any idea of doing this?
    Thanks.

    extend a new class from javax.swing.table.DefaultTableCellRenderer
    and use setCellRenderer(...) on your JTable

  • Resize column width for JTable without column headers?

    Hi,
    I find that for me to resize columns of a JTable by using
    mouse dragging, I MUST have column headers and then drag
    column headers to resize them. Is my understanding correct?
    Actually, I need to have a table without header columns.
    How can I use mouse to resize column width by dragging?
    The background for this request is that I am putting a
    complex table as another table's column header and I hope to
    be able to resizing the complex table by mouse dragging.
    Thanks very much,
    David

    Hi,
    I think you have mistake there. Try
    <style type="text/css">
    table.apexir_WORKSHEET_DATA td {
    white-space:nowrap !important;
    td[headers="DESCR"] {
    width:300px !important;
    max-width:300px !important;
    #apexir_DESCR {
    width:10px;
    max-width:300px !important;
    </style>And you can try add
    table.apexir_WORKSHEET_DATA {
    width: 100% !important;
    table-layout: fixed !important;
    }Regards,
    Jari
    My Blog: http://dbswh.webhop.net/htmldb/f?p=BLOG:HOME:0
    Twitter: http://www.twitter.com/jariolai

  • 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;
    }

  • How to refresh an existing row of a JTable

    Hi all,
    I have to refresh the data of an existing row of a JTable after some time in thread. The code snippet is
    DefaultTableModel model=new DefaultTableModel(data,columnNames);
    table = new JTable(model)
                   public boolean isCellEditable(int row, int col)
                   return false;
    Now I also add rows to this table within the run() of the thread as
    model.addRow(new Object []{sub1,sub6,sub12,sub3,sub18});
    My problem is that I want to refresh the data of this added row within the thread.
    Any help is highly appreciable. Thanks in advance.
    Regards,
    Har Krishan

    Hmmm. His qhestion does not seem to be with how to change the value of a field, but how to get the table to recognize the change. I thought such things were automatic. The model fires a value changed event and the JTable picks up the event and refreshes. I'm not sure why your table is not refreshing under these circumstances. Perhaps a more complete code snippet. Please use the open and close code tags to format your code if you include it.

  • To get the unique id of the selected row in a JTable as in Database

    Hi,
    After fetching the recodrs from the Database, I have displayed them in a JTable. Though I fetched all the columns from db, I am displying only only 2 columns, say Name and Number neither of which is unique, however I have a unique ID for each record in the db. Now when I select some row in the JTable, I need to know its unique ID (the one which is in the db) which i have not displayed in the JTable.
    Is there any API method that can store the unique ids of a table? Or how can this be done?
    Thanks in Advance.

    Although, if you don't want the Id visible in the table, then you need to remove its TableColumn from the TableColumnModel.
    Then when you want to reference the id you need to use:
    table.getModel.getValueAt(...);

Maybe you are looking for

  • How to read multiple files of different name using single file adapter

    There are two inbound locations inbound1 and inbound2 , and the files structure present in these two inbound locations are same but the files start with different names example (1)files in inbound1 starts with file1,file2... (2)files in inbound2 star

  • Problem with SAP Management console 'yellow is not changing to green'

    Hi I am starting my SAP Server from SAP Management console( ECC6.0 IDES Version). I am able to login into my system but after few minutes the server color is changing from Green to Yellow and I am not able to continue using my system. What could be t

  • 7.0.0.102 Crashes immediately after login

    After updating to Skype 7 it crashes immediately after login. I don't have facerig or FFsplit or any webcams. Windows is updated firewall is turned off. The eventlogs show this: Faulting application name: Skype.exe, version: 7.0.0.102, time stamp: 0x

  • Music downloading problem 9360

    Hi, I have a blackberry 9360... I bought the phone about 2 months ago and it was downloading songs perfectly. As of lately I'll download a song and when it gets to about a quarter of the way it'll stop downloading and say 'Error'. I only have this pr

  • Stop connecting as SID

    Below are example of two entries in my listner alert log file(log.xml). which is having CONNECT_DATA with "Service_Name" and CONNECT_DATA with "SID". For SID i made changes in "listener.ora" file. For Service Name i made changes in "tnsnames.ora" fil