What I'm trying to do is create a JTree with each cell containing normal text but also containing a right-aligned text for each cell (right-aligned to the edge of the tree, regardless of the hierarchy level).
I've tried creating my own TreeCellRenderer, but the cells' sizes are not being updated. I also tried this idea with a custom tree UI but am experiencing similar issues.
I also have tried creating a custom component with a JPanel "glued" to the right of the tree. This has been the most successful, but I have been unable to have the tree cells extend to the right and touch this extra panel:
alt text http://img718.imageshack.us/img718/3676/problem.png
You could try to use a JXTreeTable, from the SwingX package.
jxtreetable example http://blogs.sun.com/geertjan/resource/outline-tim-browser.png
You would define then such an object with two columns (one for the tree, to other for the right aligned text), and it should work out fine.
To prevent it from looking like a table, though, I would recommend you to deactivate the header (setTableHeader(null)), and use their "packing" methods, to have the columns on optimal size.
Related
I'm using a subclass of the Tree class in my project. I'm having two problems. First I would like to change the text of the not-leaf nodes when they expand or collapse. Second when expanding some nodes the tree exceeds the screen and even if scrollable is set to true, I can not scroll all the way to the bottom. To be specific the tree always shows as many nodes as in the beginning. If it begins with 10 nodes, then after expanding I will only be able to scroll the ten top nodes and not the whole tree.
While trying to figure out both points I looked for a callback on expansion/collapse, but it seems to be private. Is there any way to add a listener on expansion/collapse or other way to solve my issues?
Tree should be placed in a non-scrollable hierarchy where it can take responsibility over the scrolling e.g. in the center of a border layout on the Form.
You can override the createNode method of Tree and build any type of Component you want. It can change it's text when it's expanded based on the events and do anything you want.
I’m currently writing a custom TableCellRenderer using a JEditorPane as cell-component for a JTable. I want to make hyperlinks clickable in that component.
Therefore, I wrote a tiny hack that forwards mouse events that are fired on the Table to the specific component. The problem is, that I cannot use the viewToModel function of the JEditorPane to determine the text under the mouse cursor, because the size of my editor pane is always zero and therefore viewToModel always returns -1.
Is there any way to get the components rendered in the table’s cells to have their correct sizes set? Do you have any suggestions on doing it in another way?
Some side information: I cannot use JTextPane since I'm using the scala programming language and there is currently no implementation for it. Furthermore, I have read that it may be possible to use the native event implementation by using custom cell editors. But I could not get this working in the first place. I want that, for instance, links are highlighted by hovering over. But, as far as I can see, that is not possible with the cell editor approach, since you have to click at the cell to start editing first.
I am new to libgdx. I was referring to the documentation here TableLayout-Alignment
Similar to this example, for simplicity's sake, let's say I have a nameLabel and a nameText widgets.
So when I do
table.add(nameLabel).width(100);
table.add(nameText).width(100);
I will get two widgets of of same size adjacent to each other in the middle of outside table as by-default it is centered aligned. something like this:
Now what I want to do, I want to send "nameLabel" to the extreme left and "nameText" to the extreme right.
What I am doing is that
table.add(nameLabel).width(100).left();
table.add(nameText).width(100).right();
But it won't work, until I expand both of these widgets as explained in the example above. Can anyone explain to me, why I have to expand for this alignment to work?
Calling cell.expand() make the cell expand its size to vertical or horizontal or both. Not everybody always want the cell expand after created by default.
The left and right functions only work if the cell is expanded.
Is it possible to assign different icons to different nodes in a JTree using DefaultTreeCellRenderer.setOpenIcon()? Thanks.
The same cell renderer instance is used to render all the cells of the tree. The open icon is the little + symbol, or triangle symbol at the left of every tree node which allows to expand it (i.e. see its child nodes). I doubt this is the icon you want to change. It would be rather strange not to use the same one for all the nodes.
If you want to display a custom icon for a specific node, create a subclass of DefaultTreeCellRenderer, override the getTreeCellRendererComponent method, decide which icon to display based on the value passed to the method, and call setIcon.
See http://download.oracle.com/javase/tutorial/uiswing/components/tree.html#display for a similar example (which customized the tooltip, and not the icon, but the idea is the same).
I would like to create an interactive JTable. For this, I would like to add JPanels in the cells of the table. Once the JPanels are in the cells, I can add my various components to the JPanels thus making the table interactive. Each JPanel could have different components. Would it be possible to accomplish this and only have to create 1 table cell editor and 1 table cell tenderer. Does anyone know of a better way to do it?
Thanks
EDIT: Thanks for the responses. I actually already have a framework I am using. I just needed a JTable that users could drag and drop images in, play movies, display graphs, etc... I already have the functionality to do those things, I just needed a JPanel to add them too. I wanted it to be displayed in a JTable so the cells could be sorted, moved, add/delete rows/col, and well structured. I couldn't get it to work using the JTable, so I went ahead an created my own. Its just a JPanel that contains smaller JPanels (the table cells) using the GridLayout. It works well enough for my puposes. Just a pain to rewrite all of the functionality from scratch that a table has.
This is hard. JTable actually uses the cell renderers only for painting the cell content. I would recommend to check if a gridlayout packaged into a scrollpane would be the easier solution.
It sounds like you're trying to use JTable as a docking framework. Assuming this is the case you're better off using something like MyDoggy or JDock which allow you to decompose your GUI into multiple split pane areas.
JSplitPane may be an alternative in this context: one pane would hold the JTable, while the other displays expanded details of the selected row. A compete example using GridLayout is shown here.