Custom swing component: size


I would like to create a custom cell with a width and height that depends on the cells around it.
Can I access from the editorContext the surrounding cells?
If not, given a node, can I find the corresponding cell and its size?



Comment actions Permalink

Class CellTraversalUtil has some methods for traversing the cell hierarchy that you might find useful.

Comment actions Permalink

Hi Federico,

yes, this is possible. You may take the HorizontalLineCellProvider as a starting point. So what you basically need is the current editor cell and then use this cell to check for values. For instance:


Hope that helps.




Comment actions Permalink

@Sergej: Oh, I didn't know that one. Looks quite helpful for what we are just about to do.

Comment actions Permalink

Actually, I have a question in this context:

public void bar {
// some code
// even more code

Imagine the caret is placed at "{". For this piece of code, I'd like to navigate to "// some code" over the EditorCells. But it doesn't give me what I expected. For instance:

EditorCell selectedCell = editorContext.getSelectedCell(); // selected cell is bar()
EditorCell statementListCell = CellTraversalUtil.getNextSibling(selectedCell);

Why is the StatementList the next sibling? How do I get to "// some code"? The "leaf" methods don't help...

Any hints are greatly appreciated!


Comment actions Permalink

You can explore the cell tree using Cell Explorer (right-click somewhere in the editor -> Language Debug -> Show Cell in Explorer), the hierarchy may not be obvious just from the look of the editor. There's also DfsTraverserIterable (or CellTraversalUtil.iterateTree in current master) which you can use to walk the cell tree and manually look for an appropriate cell.

Comment actions Permalink

This helped! Thanks!

Comment actions Permalink

Thank you for all the comments, they all helped!


Please sign in to leave a comment.