HierarchicalTable child width and floating

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

HierarchicalTable child width and floating

Postby therodet » Thu Jan 26, 2006 11:50 am

I am using a lot of HierarchicalTables where the parent table has only a few narrow columns and the child component is another table that has much more data to show than its parent. It would be nice if the width of the child components wasn't constrained to the width of the parent table's columns. Perhaps instead, the child component could use its preferredWidth if set, or the parent column widths if not.

Another, related feature that I think would be handy would be if there was an option to make the child component always fit to the width of the parent table's viewport, and float in place when the parent table is scrolled sideways.
therodet
 
Posts: 37
Joined: Fri Dec 02, 2005 6:52 am
Location: Lansing, MI, US

Postby JIDE Support » Thu Jan 26, 2006 12:01 pm

If the child table preferred width is wider than parent table width, how do we manage to display the full content of child table? It will make the parent table wider too, right?

The second suggestion is a nice one. We need to think how to make it working. I guess a custom HierarchicalPanel should do the job but don't know for sure.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby therodet » Thu Jan 26, 2006 12:29 pm

JIDE Support wrote:If the child table preferred width is wider than parent table width, how do we manage to display the full content of child table? It will make the parent table wider too, right?


Yes, what I am envisioning in my mind would mean that the child component could potentially cause the parent's viewport to show a horizontal scrollbar even when the parent table doesn't need one. However, if the second feature were implemented, the first would be less important to me, since I could just put a scrollpane inside of your proposed HierarchicalPanel to allow for a child component that is wider than the viewport.

Thanks for your always prompt replies :)
therodet
 
Posts: 37
Joined: Fri Dec 02, 2005 6:52 am
Location: Lansing, MI, US

Postby therodet » Thu Jan 26, 2006 12:32 pm

Also on the topic of the HierarchicalTable, in your demo, you created a custom ScrollPane to auto-fit the child table's dimensions. Seems like this would be a handy component to include in your standard component set :wink: ... maybe add an option to allow Horizontal scrolling while auto-fitting the height
therodet
 
Posts: 37
Joined: Fri Dec 02, 2005 6:52 am
Location: Lansing, MI, US

Postby JIDE Support » Thu Jan 26, 2006 12:36 pm

I believe you can already do this yourself. In HierarchicalTable, there is a FitScrollPane class which will resize to its preferred height. You can use it in your HierarchicalPanel to do what you want.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby teresa.cea » Thu May 03, 2007 10:12 am

I have the same problem: the child table preferred width is wider than parent table width, to display the full content of child table I need the horizontal scrollbar.
I have used and modified the FitScrollPane class, to see the horizontal scrollbar I have set JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS but I don't see the horizontal scrollbar, the vertical scrollbar works fine.

private void initScrollPane() {
setBorder(BorderFactory.createLineBorder(Color.GRAY));
setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
getViewport().getView().addComponentListener(this);
removeMouseWheelListeners();
}

Is this functionality implemented?
teresa.cea
 
Posts: 6
Joined: Wed Oct 20, 2004 1:24 am

Postby JIDE Support » Thu May 03, 2007 10:43 am

If you look at the FitScrollPane, you will see we also have code to make the width of the table to be always the same as the width of the scroll pane. That's why the horizontal scroll bar never shows. I think it's really up to you how to do you want to implement this feature. FitScrollPane is just an example (not a feature of HierarhicalTable. That's why the source code of it is in the example, not in JIDE Grids) which we make the full content of the child table is always visible. If you need some other behavior, you can do it yourself.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby drewformica » Mon Apr 14, 2008 8:10 am

I've run into a similar situation where we have nested Hierarchical tables and that sometimes the child table is wider then the parent and other times the child is not as wide.

So we extended JScrollPane and added in the logic for getPreferredSize from FitScrollPane

Here is where we plug our TableScrollPane into getTableComponentFactory for the parent


Code: Select all
 
  private HierarchicalTableComponentFactory getTableComponentFactory() {
        return new HierarchicalTableComponentFactory() {
            @Override
            public Component createChildComponent(HierarchicalTable table, Object model, int rowIndex) {
                ChildContainerTableModel tableModel = (ChildContainerTableModel) model;
                BaseListingTable         childTable = createChildContainerTable(tableModel);
               
                childTable.setComponentFactory(getTableComponentFactory());
                JScrollPane pane = new ChildTableScrollPane(childTable);
                 
                TreeLikeHierarchicalPanel treeLikeHierarchicalPanel = new TreeLikeHierarchicalPanel(pane);
                treeLikeHierarchicalPanel.setBackground(childTable.getMarginBackground());

                return treeLikeHierarchicalPanel;
            }

        };
    }


I have not thoroughly tested this TableScrollPane it is a quick and dirty for us to be able to handle children that are wider than their parent for an engineering release we have - so if you see funky behavior I apologize, I jjust thought I'd post it incase it might help someone else

Code: Select all
public class TableScrollPane extends JScrollPane {
   
    public TableScrollPane(JTable table) {
        //NOTE: Important for dynamic resizing - see method comments
        ComponentListener listener = getScrollPaneComponentListener(table);
        addComponentListener(listener);
       
        //This is supposed to handle scroll bars as necessary
        setViewportView(table);
    }
   
    @Override
    public Dimension getPreferredSize() {
            getViewport().setPreferredSize(getViewport().getView().getPreferredSize());
            return super.getPreferredSize();
    }
   
    public JTable getTable() {
        return (JTable) getViewport().getView();
    }

    private ComponentListener getScrollPaneComponentListener(final JTable table) {
        return new ComponentListener() {
            @Override
            public void componentHidden(ComponentEvent e) {
                resize();
            }
           
            @Override
            public void componentMoved(ComponentEvent e) {
                resize();
            }

            @Override
            public void componentResized(ComponentEvent e) {
                resize();
            }

            @Override
            public void componentShown(ComponentEvent e) {
                resize();
            }
           
            private void resize() {
                Container tableContainer      = table.getParent();
                Double    tableContainerWidth = tableContainer.getSize().getWidth();
                Double    tablePreferredWidth = table.getPreferredSize().getWidth();
               
                if (tableContainer instanceof JViewport) {
                   
                    if (tableContainerWidth < tablePreferredWidth) {
                        //TableContainer width is smaller than preferred table width - don't auto resize the columns - allow scroll bar to display
                        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                    }
                    else {
                        //TableContainer width is bigger than table preferred width - allow the columns to grow to eat up the space
                        table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
                    }
                }
            }
        };
    }
}
drewformica
 
Posts: 71
Joined: Tue Jan 16, 2007 3:00 pm


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 18 guests

cron