JTable Header/summary  Row

Hi
I have a jtable and I want to add a summary row right under the header. I added a row and I specified in the sorting class to start from 1 instead of 0, which made my summary not sortable. but, when I scroll down, the summary row disappears.
How can I make it not disappear? the same problem with printing. I'm using the table.print method and it prints only in the first page, while I want to print on every page.
I think I should add it as part of the header? I have no idea how to do that.
any ideas or help?
Thanks,
Benbak
Message was edited by:
Benbak

I think you will find something here: http://www.physci.org/codes/tame/

Similar Messages

  • Summary row in JTable

    I have created a JTable with some information. I want to have the last row of the table as a summary row so I want it to stand out. How would I go about putting the text in the last row of the table in bold font?
    Thanks for help!

    I looked at this example, but I thought that while the structure of the tutorial is good, the code might not be so great. Take for example the number renderer class, I won't repeat it here (might violate copyright) but the setValue method gets a number instance each time it is invoked to render a cell. My understanding is that this is inefficient, as getting an instance is a fairly involved procedure (it involves looking up locale information for instance). Also the code makes heap allocations which could potentially overwhelm the garbage collector (from what I've read).
    I'm learning java, and I used the example to make a decimal renderer. The main purpose of this is to show the number for the default locale and the specified number of decimal places:
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    import javax.swing.table.DefaultTableCellRenderer;
    public class DecimalRenderer extends DefaultTableCellRenderer {
        int precision = 0;   //my addition
        Number numberValue;   //moved from setValue()
        NumberFormat nf;   //moved from setValue()
        public DecimalRenderer(int p_precision) {
            super();   //same as example
            setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);  //same as example
            precision = p_precision;  //my addition
            nf = NumberFormat.getNumberInstance();  // moved from setValue
            nf.setMinimumFractionDigits(p_precision);  // my addition
            nf.setMaximumFractionDigits(p_precision);  // my addition
        public void setValue(Object value) {
          if ((value != null) && (value instanceof Number)) {
            numberValue = (Number) value;   // re-use the class member, not a local member
            value = nf.format(numberValue.doubleValue()); // same as example
          super.setValue(value);
      } By re-using the number instance and making the variables class level fields as opposed to local members of the setValue function, I expect to avoid the problems I mentioned above.
    Have I understood the situation correctly? I guess that experienced people would be aware of this, but I get annoyed by the examples I see as they typically give 'expedient' examples which seldom represent 'best practice'. Often, I can see that something probably isn't best practice, but I don't know what the best practice is.

  • How to add  ComboBox in Jtable Header

    Hello everyone,
    I want to add a Combox box in JTable Header .Basically it works as central access to whole table e.g. by selecting delete row in combo box then it should delete the current selected row.If somebody has any idea please share it.
    Thanks in advance.

    The individual headers are not Swing components and therefore do not respond to mouse events in the same way as Swing components. Why don't you just have a popup menu that is positioned over the currently selected row? If you want to apply an action to all selected rows then have a set of buttons placed above the table header.

  • JComboBox in the JTable Header - TableCellEditor problem

    Hi,
    I have added JComboBox into the JTableHeader. But I can't Edit that combobox. It is looking like an icon. I have added JPanel into the JTable Header Row. In JPanel i have added one JLable and JComboBox.
    Please any one of you give me the solution.
    Thanks,
    Shrini V.

    The table will display what ever value it has in its model. When you add the row, there is no data in the second column. You'll have to supply it.
    public void insertMyRowCombo (Object [] r,
                                      JComboBox c,
                                      JTable t) {
           // {"rut", "puntaje cas", "beneficio", "fecha inicio", "fecha termino", "monto"};
            DefaultTableModel tm = (DefaultTableModel) t.getModel();
            tm.addRow(r);
            TableColumn col = t.getColumnModel().getColumn(2);
            col.setCellEditor(new DefaultCellEditor(c));
            tm.setValueAt( c.getItemAt(0), 0, 2); //manually supply the value to col 2
        }ICE

  • Multiple Icon on Jtable header

    Hi All:
    Any one had used multiple icons on JTable header ? According to the user's clicking positon under one column, one of these icons should change such as changing from sorting up arrows to sorting down arrows.
    I got the mouse clicking position on the header and column, then depend on the location, I wanted to perfrom different things. But I have not figured out if I should call header renderer to perform the repaint or not ? If I use JTable header render, how should I confine the one column that change should happen? I don't want to have all columns repainted. If I treat each column indivisually, should I reconstruct the JTable ? I used SortableTableModel to create the JTable.
    Any help is appreciated.
    Regards

    Here's the idea. I didn't test thisclass JComponentCellRenderer extends JButton implements TableCellRenderer {
        public JComponentCellRenderer (ImageIcon ii) { super("",ii); }
        public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
            setText(value.toString());
            return this;
    }and thentblChanges.getColumnModel().getColumn(0).setHeaderRenderer(new JComponentCellRenderer(new ImageIcon( "CheckBoxHeaderImage" )));

  • JTable Multi ColumnName Rows and Mac

    I do the following to get multi rows for a single column name. Example:
    Column Name 1 =
    Quiz
    SessionName
    100 points
    This code works for Windows but not Mac. The JList appears behind Mac's attemp to make a JTable header. It seems like Mac's component is heavyweight. Anyone know a work around?
      TableCellRenderer iconHeaderRenderer = new DefaultTableCellRenderer()
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
          if(value.toString().indexOf("\r\n") == -1)
            setText((value == null) ? "" : value.toString());
            setIcon(null);
            setBorder(UIManager.getBorder("TableHeader.cellBorder"));
            setHorizontalTextPosition(JLabel.LEFT);
            setHorizontalAlignment(JLabel.CENTER);
            return this;
          else
            JList multiRow = new JList();
            multiRow.setOpaque(true);
            multiRow.setForeground(UIManager.getColor("TableHeader.foreground"));
            multiRow.setBackground(UIManager.getColor("TableHeader.background"));
            multiRow.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
            multiRow.setCellRenderer(new MyCellRenderer());
            String str = (value == null) ? "" : value.toString();
            BufferedReader br = new BufferedReader(new StringReader(str));
            String line;
            Vector v = new Vector();
            try
              while ((line = br.readLine()) != null)
                v.addElement(line);
            catch (IOException ex)
              ex.printStackTrace();
            multiRow.setListData(v);
            setBorder(UIManager.getBorder("TableHeader.cellBorder"));
            return multiRow;
      };

    bump

  • In a ADG is it possible to have a pie chart in a summary row?

    In a ADG is it possible to have a pie chart in a summary row?
    The segments would be worked out from a funtion applied to the data
    in that grouping.
    Thanks :)

    The JTable is a tabular component. So it will always have enough columns to display the maximum row length. you don't have to pur a value in every cell.
    There are methods in JTable to remove horizontal and vertical lines and you could implement a renderer to make empty cells look like the background.
    Cheers
    DB

  • Highlight JTable Header

    Hello,
    I want to be able to change the color of a JTable header of a column ie highlight it when a user clicks on the table header. Is there a way to do this? I'vd done a google search but nothing seems to address this. Any help is much appreciated. Thanks.
    vyang

    Try this piece of code on for size. The HeaderRenderer class is far from complete but it should give you something substancial to work with. This renderer also using GradientPainting to give you an extra boost in terms of appearance.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.datatransfer.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.filechooser.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    public class HeaderRenderer extends DefaultTableCellRenderer implements
                    MouseListener, MouseMotionListener {
        Color bg = new Color(242,242,255), fg = Color.black;
        Rectangle paintingRect = null,
            lpr = null; //last painted rect
        JTableHeader header = null;
        public boolean isOnCol = false, highlightClickedCol = false;
        private int paintingCol = -1, clickedCol = -1, currentCol = -1;
         * Buffer gradient paint.
        GradientPaint gp = null, hoverGradient, columnGradient;
         * The current sorting state of the columns
        SortOrder sortOrder = null;
        public HeaderRenderer() {
            super();
            setFont( getFont().deriveFont(Font.BOLD) );
            //setBackground( bg );
            setForeground( fg );
            setOpaque(false);
            setBorder( BorderFactory.createCompoundBorder (BorderFactory.createMatteBorder(0,0,1,1, new Color(200,200,230) ),
                            BorderFactory.createEmptyBorder(4,7,4,4)) );
            setHighlightClickedColumn(true);
        public void setColumnGradient(GradientPaint gp) {
            this.columnGradient = gp;
        public void setHoverGradient(GradientPaint gp) {
            this.hoverGradient = gp;
        public GradientPaint getColumnGradient() {
            return columnGradient;
        public GradientPaint getHoverGradient() {
            return hoverGradient;
        public void setHighlightClickedColumn(boolean b) {
            highlightClickedCol = b;
        public void paintComponent(Graphics g) {
            Rectangle rect = paintingRect;
            Graphics2D g2 = (Graphics2D)g;
                g2.setPaint(gp);
                g2.fillRect( 0, 0, rect.width, rect.height );
            FontMetrics fm = g.getFontMetrics();
            int strWidth = fm.stringWidth( getText() );
            /*if(currentCol == clickedCol) {
                if( sortOrder == SortOrder.ASCENDING )
                    new ArrowIcon( ArrowIcon.UP ).paintIcon(this, g, strWidth + 15, 8);
                else if(sortOrder == SortOrder.DESCENDING )
                    new ArrowIcon( ArrowIcon.DOWN ).paintIcon(this, g, strWidth + 15, 8);
            sortOrder = null;
            super.paintComponent(g);
        public void attachListener() {
            header.addMouseListener(this);
            header.addMouseMotionListener(this);
        public void mouseEntered(MouseEvent e) {
            isOnCol = true;
        public void mouseExited(MouseEvent e) {
            isOnCol = false;
            paintingCol = -1;
            header.repaint();
        public void mouseReleased(MouseEvent e) {}
        public void mouseClicked(MouseEvent e) {
            clickedCol = header.columnAtPoint( e.getPoint() );
        public void mousePressed(MouseEvent e) {}
        public void mouseMoved(MouseEvent e) {
           // isOnRow = true;
            paintingCol = header.columnAtPoint( e.getPoint() );
            paintingRect = header.getHeaderRect( paintingCol );
            header.repaint( paintingRect.x, paintingRect.y, paintingRect.width, paintingRect.height );
            if(lpr != null) {
                header.repaint(lpr.x, lpr.y, lpr.width, lpr.height);
            lpr = paintingRect;
        public void mouseDragged(MouseEvent e) {
            //isOnRow = true;
            paintingCol = header.columnAtPoint( e.getPoint() );
            paintingRect = header.getHeaderRect( paintingCol );
            header.repaint( paintingRect.x, paintingRect.y, paintingRect.width, paintingRect.height );
            if(lpr != null) {
                header.repaint(lpr.x, lpr.y, lpr.width, lpr.height);
            lpr = paintingRect;
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
             boolean hasFocus, int row, int col) {
            currentCol = col;
            if(header == null) {
                header = table.getTableHeader();
                attachListener();
            if(table.getRowSorter() != null && table.getRowSorter().getSortKeys().size() > 0 ) {
                java.util.List<? extends RowSorter.SortKey> keys = table.getRowSorter().getSortKeys();
                for(RowSorter.SortKey key: keys) {
                    if(key.getColumn() == col) {
                        sortOrder = key.getSortOrder();
            Rectangle rect = table.getTableHeader().getHeaderRect(col);
            if( (isOnCol && paintingCol == col) || (clickedCol == col && highlightClickedCol)  ) {
                gp = new GradientPaint( rect.x, rect.y + rect.height, new Color(200,220,235),
                                    rect.x, rect.y, new Color(230,235,250)  );
                setForeground( new Color(50,50,50) );
            } else {
                gp = new GradientPaint( rect.x, rect.y + rect.height, new Color(235,240,245) ,
                                        rect.x, rect.y, new Color(245,250,255) );
                setForeground( new Color(100,120,160) );
            paintingRect = rect;
            //JLabel renderer = new JLabel();
            setText( value == null ? "" : value.toString() );
            //setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
            //   brdr) );
            return this;
        public static void main(String[] args) {
            DefaultTableModel model = new DefaultTableModel(20,5);
            JTable table = new JTable( model );
                table.getTableHeader().setDefaultRenderer( new HeaderRenderer() );
            JFrame frame = new JFrame("Header Renderer Test");
                frame.add( new JScrollPane(table) );
                frame.pack();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
    }ICE

  • How can i create a grid with summary row

    Hello Professionals,
    I'm wondering how could i create a grid like the grid below, i want to create a grid with summary row,
    i have tried to create it using collapsing but it didn't work as required.
    Any suggestions?, i want to know just the starting point so i can make deep investigations.
    Thanks in Advance,

    Hi Karem,
    this can be achieved by just assigning a datatable containing the data plus some formatting of grid. Meaning there is no feature for that.
    The datatable can be filled manually or by sql query. Then you have to attach some events for updating the values ( validate after for gid item ).
    A small example for a sql query showing last month quotations and orders with summary :
    select 1 as Sort,cast(DocNum as varchar) as DocNum,DocTotal,convert(varchar, DocDate,104) from OQUT where DocDate between  DATEADD(month, -1, GETDATE()) AND GETDATE()
    UNION ALL
    Select 2 as Sort,'Summary ( Quotation ) : ',sum(DocTotal), convert(varchar,  DATEADD(month, -1, GETDATE()),104)+' - '+convert(varchar,   GETDATE(),104) from OQUT where DocDate between  DATEADD(month, -1, GETDATE()) AND GETDATE()
    UNION ALL
    select 3 as Sort,cast(DocNum as varchar) as DocNum,DocTotal,convert(varchar, DocDate,104) from ORDR where DocDate between  DATEADD(month, -1, GETDATE()) AND GETDATE()
    UNION ALL
    Select 4 as Sort,'Summary ( Order ) : ',sum(DocTotal), convert(varchar,  DATEADD(month, -1, GETDATE()),104)+' - '+convert(varchar,   GETDATE(),104) from ORDR where DocDate between  DATEADD(month, -1, GETDATE()) AND GETDATE()
    ORDER by Sort
    regards,
    Maik

  • How do i change the cursor on a jtable header when clicked for sorting?

    here is my question, how do i change the cursor on a jtable header when I click the header for sorting?
    I think it is suppose to be in the fragment of code where the header listener is implemented for sorting, but I'm not quite sure what is the exact component that holds everything so that i can change the cursor...
    below is what I've tried, but it doesn't seem to work... thank you
    public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new
    MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    TableColumnModel columnModel =
    tableView.getColumnModel();
    int viewColumn =
    columnModel.getColumnIndexAtX(e.getX());
    int column =
    tableView.convertColumnIndexToModel
    (viewColumn);
    System.out.println("column = "+column);
    if (e.getClickCount() == 1 && column != -1) {
    System.out.println("Sorting ...");
    Cursor oldCursor =
    tableView.getRootPane().getCursor();
    System.out.println("oldCursor.getType()
    = "+oldCursor.getType());
    if (oldCursor.getType() !=
    Cursor.WAIT_CURSOR){
    JComponent parentPane =
    tableView.getRootPane();
    parentPane.getContentPane().setCursor
    (new Cursor(Cursor.WAIT_CURSOR));
    parentPane.setCursor(new Cursor
    (Cursor.WAIT_CURSOR));
    Cursor newCursor =
    parentPane.getCursor();
    System.out.println("newCursor.getType
    () = "+newCursor.getType());
    int shiftPressed = e.getModifiers(
    &InputEvent.SHIFT_MASK;
    boolean ascending = (shiftPressed == 0);
    //System.out.println("tableView.getRootPane()
    is "+tableView.getRootPane().getRootPane());
    sorter.sortByColumn(column, ascending);
    tableView.getRootPane().setCursor(new Cursor
    (Cursor.DEFAULT_CURSOR));
    //System.out.println("Done sorting");
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
    }

    Hi,
    Try setting the cursor for the table header.
    table.getHeader().setCursor(Wait_Cursor);
    Bala.

  • How to find out if JTable's selected row is visible?

    Hello there,
    Given:
    a JTable is inserted into a JScrollPane and the number of rows in the table is greater than the vieport size.
    A random row within the table gets programmatically selected.
    How to find out if the selected row is visible in a JTable visible area?
    Your help will be greatly appreciated.
    Tim

    That will make the row visible, but not answer whether it was visible
    in the first place. Try something like:
    public boolean isRowVisible( JTable table, int row ) {
        Rectangle rect = table.getBounds();
        int rowHeight = table.getRowHeight();
        int viewHeight = table.getParent().getHeight();
        int max = rect.y - viewHeight + 1;
        int rowPos = - rowHeight * row;
        return ( rect.y >= rowPos && rowPos > max );
    }assuming all rows have the same height.
    : jay

  • Not able to edit the JTextField under the JTable header

    Hi,
    As per my requirement, i need to add the text field in JTable header for filtering the table records.
    i have added the text field but not able to enter any value (it is disabled).
    Can anyone please help me on this?

    Welcome to the forum.
    After reading how to format Code in this forum (SQL and PL/SQL FAQ ),
    please show us the code of your TableHeader implementation.
    bye
    TPD

  • Using Previous function in summary rows?

    Hi,
    I have a requirment, where I have to use the value got in previous column in the summary row.
    The scenario is as follows.
    There are Product, Quantity on Hand , Order Type and Date column. I am using cross tab, As I have to use the details of columns for each date.
    So date will be spreaded across table as there are more dates.
    In summary column, I would like to do a calcuation for each date. And I should use the calculated amount on one date in the next date and the calcuation continues.
    I am trying to use previous function, but its showing computation error.
    I am attaching a excel sheet with a sample example for easy understanding.
    The calculation which I used in summary row is avialble in formula section, when we select the column.
    Thanks in Advance.
    Regards
    Gowtham

    Hi BOCP,
    Yes, I am trying to use this function in Summary after Break.
    Sorry, I missed out attachment. And I didn't find a way to attach it.
    Suresh,
    I didn't find last() function in WebI Editor. I am using BO XI R2.
    Thanks a lot.
    Regards,
    Gowtham Sen.

  • Tabular form calculated summary row

    Hopefully this may be a quick question with either a yes or a no
    I have a tabular form with columns
    Project Name , Wk1 , Wk2 , Wk3 etc ,
    basically so PM's can track the hours against a project
    I have used the sum checkboxes to create a summary row
    but they also want a row that calculates how many hours remaining for each week under the week no cols , obviously subtracted ffrom the hours budget for each week assigned to the project and person
    I've done the summary and calculation in a view but this isn't acceptable as a UNION query in a tabular form
    I've also tried another region under the Tabular form but as the project name is a variable length its not easy keeping the Wk cols aligned
    thanks in advance
    Chris

    Hi Gus/Paul,
    I had the same requirements as you, resulting from the fact that newly added rows may not be visible to the user until he/she has scrolled down sufficiently, but, by lowering my standards (something I excel at :D ), I was able to find an acceptable compromise.
    As you probably noticed yourselves, when you "edit" the ADD button, you can see that a call is made to the addRow() javascript function. I therefore took a look at the javascript code - foolish really as I am an oracle DBA from the Jurassic period. Needless to say it scared the pants off me... So, fuelled by cowardice, I snatched at an inferior-but-dead-easy-to-implement alternative solution whereby the page is automatically "scrolled" to the bottom of the form when the "ADD" button is clicked.
    Should this "cop out" work for you, you can implement it in the following way:
    1. Create a new HTML region immediately after the tabular form, containing the following source: <font color="blue">&lt;a name="bottom_of_page"&gt;&lt;/a&gt;</font>
    2. Amend the action when the "ADD" button is clicked to scroll down to the new region by doing the following:
    - edit "ADD" button
    - Go to "Action when button Clicked" section
    - Amend "URL Target" from
    <font color="blue">Javascript:addRow();</font>
    <br>to
    <font color="blue">Javascript:addRow();window.location='#bottom_of_page'</font>
    <br>
    <br>Regards,
    Amr.

  • Adding a dynamic summary row for a spark data grid

    i'm looking for a solution for a spark data grid.
    by clicking on a row it will become larger and will show under the original row a some kind of a summary text with no realtion to columns.
    is there a summary row option for a spark datagrid that can shown by clicking on the row?

    Why would you need to make this part of the DataGrid? Just create some kind of view and bind it's data to the selectedItem of the DataGrid.
    *edit*
    Ohhhh, I see that you want it to display under the item. I believe you can do what you need in the skin, but I haven't had a chance to use the spark DataGrid yet so I can't say for sure. I know it has a feature to skin the selection, so I'm sure you can use that to do what you need.

Maybe you are looking for

  • My WD hard drive won't "mount" it shows in disk utility but can't be repaired. I'm thinking this is a software issue since the disk is being recognized.

    I I have a WD drive that won't "mount". Tried repairing, turning off and back on, unplugging and nothing has worked. Can anyone help?

  • HELP!!! I can't find my work

    During the process of editing clips in iMovie, the external firewire drive containing the movie came unplugged and when I quickly secured the plug and tried to save my work, the computer would not respond. Luckily, I felt better because I had just sa

  • Cannot close a tab

    I have Firefox 3.6.12. In the last couple of days I have been having problems cosing tabs. I click on the cross on the tab but nothing happens. It only happens occasionaly on 1 tab. I can close other tabs in the session without a problem. It is not s

  • APP-FND-01516

    Hi I am facing problem with the error APP-FND-01516, while opening a forms in R12.1.1 Instance. I am unable to connect to database from application Side. any on help me on this.... Thanks in advance......

  • Remote debugging with VC

    Has anyone had success connecting remotely to a WebLogic. I am running webLogic 5.1 on Solaris using sun's JDK 1.2 and trying to connect to it from VisualCafee running on an NT machine. I can successfully connect to the WL process from JDB but not fr