Merging Cells in  JTable

I want to merge cells of JTable. I searched on net about this and found that there is no direct API available for doing this.
After visiting many forums I found that jp.gr.java_conf.tame.swing.table package is needed to merge cells. Where will I get this package from and is this package for free? Other packages for merging cells will also do.
Thanks in advance

Pranav_Tipnis wrote:
I found that jp.gr.java_conf.tame.swing.table package is needed to merge cells. Where will I get this package from and is this package for free? Yes, this package is for free. You get it from here: [http://www.codeguru.com/java/articles/137_tame1.zip]
However, the component is complicated and difficult to adapt and debug in case you need special functionality.

Similar Messages

  • Merge cells in JTable.......

    Plz some help me out ......i want to merge two consecutive cells of a row in one cell in JTable......... how to do that.....give some code if possible....

    Well, as a new member you should learn to search the forum first before posting questions. Using keywords like "jtable merge cell" will find other postings on this topic. Some with solutions some without, so you will need to read a few and decide on the approach you want to take.

  • Merge cell in JTable

    Hi
    I have some problem with JTable that have merged cell.
    Have you got any examples for JTable with merged cell.
    Thank in advance

    check this....there are plenty of examples....
    http://www2.gol.com/users/tame/swing/examples/JTableExamples4.html

  • How to merge cell in jtable

    i want to merge the cell in the jtable , as one cell requires more space than other kindly tell me how to do so

    Try http://codeguru.earthweb.com/java/articles/139.shtml

  • Merging cells in JTable...help

    Can someone give me some direction into how I can handle this....

    After hours of poking around, I figured out all i needed was an extended BasicTableUI class. With the help of tames MergedCell example, I havepulled out what I need out of his class and stripped it down alot to what I needed. hopefully this will help others also...
    package foo;
    import java.lang.*;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.plaf.basic.*;
    /*This class extends BasicTableUI class which is responsible for drawing the cells in a JTable
    Functionality has been added to this class to allow a column cell to be spanned, or merged across
    the entire length of the table.*/
    See the paintRow() method to define when and how to span the cells.
    public class LogicTableUI extends BasicTableUI
         public void paint(Graphics g, JComponent c)
              //get the rectangle bounds of the current graphic to be drawn
              Rectangle oldClipBounds = g.getClipBounds();
              //makes a new rectangle the same size as the current rectangle
              Rectangle clipBounds = new Rectangle(oldClipBounds);
              //gets the width of all combined columns and assigns to tableWidth
              int tableWidth = table.getColumnModel().getTotalColumnWidth();
              //sets the width of the new rectangle to equal the either the current rect size of the table width
              clipBounds.width = Math.min(clipBounds.width, tableWidth);
              //Sets the current clip to the rectangle specified by the given coordinates
              g.setClip(clipBounds);
              //define the first and last rows that are visible
              int firstIndex = table.rowAtPoint(new Point(0, clipBounds.y));
              int lastIndex = table.getRowCount()-1;
              //define a rowRect. This is a rectangle spanning the entire visible part of the table
              Rectangle rowRect = new Rectangle(0,0,tableWidth, table.getRowHeight() + table.getRowMargin());
              rowRect.y = firstIndex*rowRect.height;
              //for every row that is visible, paint it
              for (int index = firstIndex; index <= lastIndex; index++)
                   //is the clipBounds of the current object to be drawn in this row?
                   if (rowRect.intersects(clipBounds))
                        paintRow(g, index);
                   //move to next row
                   rowRect.y += rowRect.height;
              g.setClip(oldClipBounds);
         private void paintRow(Graphics g, int row)
              //define rect as the current graphic objects bounds
              Rectangle rect = g.getClipBounds();
              //the graphic has not been drawn yet
              boolean drawn = false;
              //define how many columns we have to draw for this row
              int numColumns = table.getColumnCount();
              //for every column in the row, paint it
              for (int column = 0; column < numColumns; column++)
                   //define cellRect
                   Rectangle cellRect = table.getCellRect(row,column,true);
                   int cellRow;
                   int cellColumn;
                   cellRow = row;
                   cellColumn = column;
                   if (cellRect.intersects(rect))
                        drawn = true;
                        DefinitionTableModel tblmod = (DefinitionTableModel) table.getModel();
                        try
                             LogicGroup grp = tblmod.getLogicGroupByRow(cellRow);
                             //is this a statement row? If so, apply special treatment to the cell,
                             //otherwise paint the cell normally
                             if (grp.getEnd()==cellRow)
                                  //We are on a row we want to span. If its the 1st column, increase
                                  //the width of the rectangle to span the entire table width and
                                  //call paintCell. Otherwise, do not even paint the cell.
                                  if (cellColumn==0)
                                       cellRect.width=table.getColumnModel().getTotalColumnWidth();
                                       paintCell(g, cellRect, cellRow, cellColumn);
                             else
                                  paintCell(g, cellRect, cellRow, cellColumn);
                        catch(Exception e)
                             e.printStackTrace();
                   else
                        if (drawn)
                             break;
         private void paintCell(Graphics g, Rectangle cellRect, int row, int column)
              int spacingHeight = table.getRowMargin();
              int spacingWidth = table.getColumnModel().getColumnMargin();
              Color c = g.getColor();
              g.setColor(table.getGridColor());
              g.drawRect(cellRect.x,cellRect.y,cellRect.width-1,cellRect.height-1);
              g.setColor(c);
              cellRect.setBounds(cellRect.x + spacingWidth/2, cellRect.y + spacingHeight/2,
              cellRect.width - spacingWidth, cellRect.height - spacingHeight);
              if (table.isEditing() && table.getEditingRow()==row &&
                   table.getEditingColumn()==column)
                   Component component = table.getEditorComponent();
                   component.setBounds(cellRect);
                   component.validate();
              else
                   TableCellRenderer renderer = table.getCellRenderer(row, column);
                   Component component = table.prepareRenderer(renderer, row, column);
                   if (component.getParent() == null)
                        rendererPane.add(component);
                   rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y,
                        cellRect.width, cellRect.height, true);
    //end of class

  • Merge cells in a JTable

    Hi there,
    I'm building a class which contains a JTable, and I'd like to be able to merge cells (both rows and columns, it depends on). I've just searched help on this forum, but in many topics, answers specify a link to
    http://www2.gol.com/users/tame/swing/examples/JTableExamples4.html
    or something like that, but this link is not enabled.
    Could someone give me some help, please ??
    Thanks.

    So I found the issue, and I'm gonna talk about it, because I think many people could be interested.
    Thus, 2 lines need to be changed. Those line are identical, and are as follows :
    TableCellRenderer renderer = aColumn.getHeaderRenderer();You just have to modify it with the following code :
    TableCellRenderer renderer = header.getDefaultRenderer();Those 2 lines are located in the paintCell() and the getHeaderHeight() methods.

  • Merge table cells of JTable

    Can we merge two cells of JTable, the way we do it in html using rowspan and colspan?

    no, that's unsupported. There are some (partly oldish, google should help) experiments out there - but beware: they all require tweaks on the level of the ui-delegates which isn't a real option most of the time.
    Cheers
    Jeanette

  • Ask for suggestion: merge cell or multiple jtable

    I would like to have a jtable like this:
    +----------+------+------+------+-----+
    | 1.Item no|2.Desc|3.Type|4.Size|5.Qty|
    +----------+------+------+------+-----+
    |    001   |  ... |  A1  |  3   |  5  |
    |          |      |------|------|-----|
    |          |      |  A2  |  2   |  6  |
    +----------+------+------+------+-----+
    |    002   |  ... |  A1  |  4   |  4  |
    |          |      |------|------|-----|
    |          |      |  A3  |  2   |  6  |
    +----------+------+------+------+-----+For each item, it would have say, 2 types (2 rows beginning from the third column).
    The question is, I'm now considering whether 1)i should use multiple jtables, one from column 1 -2 and the other from column 3 to 5. OR 2)merge cells
    In fact, i just have thought of this 2 methods and not yet implemented them yet. Any suggestion?
    Many thanks,
    Pippen

    Thanks thahn2 but I 've tried out the examples before and found them not so useful for me. And some of them even have problems running on jdk1.4.
    Any suggestion on either choice will be welcomed. (or even other suggestions)

  • How to Merge Cells in a JTable?

    First, a brief background. I have a 1.3.1 Swing application, and have a custom table framework that is extended from Swing. My table model manages row classes. Each row class has its own collection of renderers and editors. Renderers and editors are never shared; each cell has its own. My custom table asks each row for the renderer/editor as needed. This allows the GUI programmer to customize every cell of a row class, down to the renderer/editor, including which cells are editable. Essentially, my custom table framework puts all the brains into row classes. Each screen has its own row class. So, it's very granular but very powerful. However, I need more power.
    I need a way to merge cells across columns (column spanning). These merged cells do NOT need to be editable for now. I don't know how I can get the table to render one cell across others in the same row. I suspect this is largely a painting issue, and could really use some help.
    Thanks!
    Andy

    Thanks for the direction, Ian! That got me on my way.
    I subclassed BasicTableUI and copy-pasted the private methods into my subclass, and made them protected. I then modified the paintCell( ) method to change the rendering for the particular table row I'm interested in (test case).
    To make the first cell span the entire row, I changed the width of the painting rectangle to be the width of the table, instead of the width of the cell. I also had to NOT render any other cells in that row, so they wouldn't "interfere" with the first renderer. In other words, if I allow cell 3 to be rendered, it will prevent cell 0 from spanning, since cell 3 is rendered AFTER cell 0.
    Here's an example of my proof-of-concept (POC):
    // For row 5, only render cell 0
    if (row == 5) {
        if (column == 0) {
            rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y, table.getWidth(), cellRect.height, true);
        return;
    }You can see that only cell 0 will be rendered, and it will be as wide as the table.
    My next step will be to experiment with multiple spans in the same row, and then having a cell in the middle span the entire row. I'll post my results for the sake of posterity.

  • Equivalent to SpreadSheet? (I need to merge cells)

    Hey all,
    I'm making a program dealing with scheduling.
    Now i need something that works as a Spreadsheet.
    a lot of you may say 2 use JTable,
    but there's a problem with that idea, i can't merge cells.
    For example
    The Columns are days of the week, Rows are Activities
    i have an activity that is 3 days long,
    i want that activity/cell to be 3 cells long( like in excel when you merge cells).
    any ideas on how i can achieve this? or alternative ideas?
    any help will be greatly appreciated.
    avdzm
    Message was edited by:
    avdzm

    Hi,
    Browse though excellent blog at
    http://www.jroller.com/page/santhosh
    Excellent leads n discussion there.
    Cheers
    Ravi

  • Excel export are merging cells for data on multiple lines !

    Hello,
    I'm using Crystal Report XI R2, when we are doing an export to Excel with have an unexpected formatting.
    For example the value of the name is on 2 lines:
    => So, on Excel the result is on 2 lines but merged. We want to have this result only on one cells.
    Remark: if we delete the 2nd lines, because cells are merged we obtain the expected result.
    Proposal A:
    Are they any set-up available concerning the formatting of Excel ?
    Proposal B:
    Could we run some VBA when we click on Export button to make queries on the Excel ?

    When they introduced Unicode support in Crystal 9 (I believe), they had to completely re-write the export routines. At that time, they made a decision to change the functionality of the excel export. Crystal is attempting to remain absolutely faithful to the graphical layout of the report as you see it in the viewer. So it creates merged cell sections, empty columns between columns, and empty rows to give you as close to exactly what you see in the viewer as possible. Unfortunately, the result is typically less than useful. Iu2019ve had several conversations with Business Objects (now SAP) with regards to this when they changed it between versions 8.5 and 10, and they have no intention of changing the functionality as it now exists.
    There is a document which is now likely somewhere on the SAP portal that explains what you need to do to obtain the best results when exporting to excel.
    The jist of it is this:
    Line up all of the columns detail data with thier headers, and make sure that data fields are the same size as thier headers. 
    Line up all rows (headers and detail rows). (ie: select everything in the row, right click, align tops, and make the same height)
    cram everything as close together as possible. zero space in the report translates to zero extra collumns and rows in the export.
    the other option is to use the export to data only functionality, but that may not be what you're looking for either.

  • Excel Merge Cells.vi throws an undefined error in Excel 2013?

    Basically, I can't write text into an Excel spreadshoot using the Report Generation tools.
    Using LabVIEW 2013 (SP1) I am writing to individual cells in an Excel (2013) template.
    The error is coming from the Report Generation Toolkit>Excel Specific>Excel Easy Text.vi.>Excel Merge Cells.vi.
    Inside of the "Excel Merge Cells.vi" is an "Invoke Node.Range". When the program hits this point, it throws out an undefined error.
    My code has been running on multiple platforms in multiple programs with no problems using Office 2010.
    NASA upgraded our Office Suit to 2013. I am now throwing an undefined error ( -2146827284).
    I've got a service request in and have talked to an engineer. THey are looking at the problem. However, I thought I would throw it out here and see if anyone had seen this particular problem.
    Bryan Alexander

    Problem found, workaround implemented.
    When you use the "New Report.vi", you have to wire in one of four choices for the state of the window. "Maximized", "Minimized", "Normal" and "No Change". If you use the "Excel Easy Text.vi" to insert data into an Excel 2013 Spreadsheet, it will generate an error if you opened the Excel file in "Minimized" mode. The other three states work fine.

  • Smartview 11.1.2.1.103 problem: Merged cell in HFM workspace is unmerged in smartview

    I have an error here in smartview 11.1.2.1.103. In HFM workspace, the form I designed has merged cell in row1. But I open the same form in smartview, row1 is not longer merged. Does anyone have the same problem?
    PS: I've already set the option: excel formatting in smartview.

    Hi,
    thanks for your answers. From all I could find out from Oracle support, I'll have to wait until 11.1.2.1 is GA and then try again :-(
    Or will there be a patch for 11.1.2.0 as well?
    Best regards,
    Markus

  • Takes a Long time to merge cells

    Why does it take me forever to merge 4 cells in a table that
    has over 100 rows. Is there anything that I can do to speed up the
    process?

    Never merge cells? I rarely do this (of course I rarely use
    tables, too) -
    instead, I will stack tables vertically when I need a new
    cell
    configuration.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "PamVa" <[email protected]> wrote in message
    news:f30u4t$o7u$[email protected]..
    > Why does it take me forever to merge 4 cells in a table
    that has over 100
    > rows. Is there anything that I can do to speed up the
    process?

  • Is there a way of merging cells (not columns) in a Flex Datagrid?

    Hello everyone!
    I'm new to Flex and I have been searching for a solution to this problem for two days now, so any help would be really appreciated!
    I have a datagrid of, lets say x columns of fixed size, with the ability to add or remove rows dynamically. When adding a row o popup comes up and lets the user determine the positions(order) and widths of the desired cells of the row. So what I want to do is to be able to merge cells of the new Datagrid row appropriately, to satisfy the user's choices. Thats the general idea.
    Is there a way to have a Datagrid (or other similar component) with different cell number and widths for each row in Flex? I need a component similar to the Datagrid because I want to be able to select rows and process their data.
    Any idea would be very helpful as I'm pressed for time and I could use someone's experience to search in the right direction and not loose time.
    Thanks in advance!

    Thank you very much for your response. I finally did what I wanted without using a Datagrid. I used a Table Flex Component (which extends Flex Grid) that I found here:
    http://code.google.com/p/flex-table/#Demo
    I downloaded the source and changed some things to make it work as I need.

Maybe you are looking for

  • More Guru Winners for February 2015 in the System Center category and many others!

    It's been a busy week that also saw the TECHNET WIKI SUMMIT 2015 Then we had the results for February's TechNet Guru competition ALSO posted! http://blogs.technet.com/b/wikininjas/archive/2015/03/19/technet-guru-february-2015.aspx Below is a summary

  • Lightroom = Overrated, misdesigned and buggy.

    So I have been using the V1.0 version of Lightroom, and all I can say is that it is overrated and most of it is just plain junk. Don't get me wrong, the DEVELOP module is extraordinarily good, really really good, but the DEVELOP module has been surro

  • Export Controller stopped working

    I am so lost here, can not open Quicktime I get this error, and I have tried to uninstall and reinstall in every mode I can and its still comes up, Please someone help me... Product Export Controller Problem Stopped working Date 1/27/2011 3:40 PM Sta

  • Mail sent to me shows wrong name in to: field

    I've been seeing this problem for quite a while. Certainly since Yosemite was launched. A small, but significant proportion of email sent to me shows an incorrect name in the To: field. If I hover over it to see the email address, they have been sent

  • I have a new iMac.  How do I transfer my files from my iPod into Itunes?

    How do I transfer my music files from my Ipod to my Imac?  It appears to be simple to sync the Imac to the Ipod, but how to I put what I have on my Ipod on my new Imac?