Win a copy of Rust Web Development this week in the Other Languages forum!

Carvel Baus

Greenhorn
+ Follow
since Jan 15, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Carvel Baus

Francois,

Thank you for your input. I actually created this accordion panel because the JSplitPane was so difficult to work with where one would need more than 2 or 3 split panels. Using a custom layout manager, I allow the user to add as many jpanels as they like, each having a header and being able to hide/show and hopefully soon, resize by dragging.

It turns out that what I need is to implement the MouseMotionListener interface and then have the layout manager respond appropriately to each event as it occurs. The most challenging piece of it is figuring out which things need to move when one is getting resized. A straight-forward problem but not so obvious a solution - trial and error are my friend

thanks again for your input.
12 years ago
I have implemented a custom layout manager to create an accordion panel (like in Outlook, visio, entourage, etc.) The basic behavior is each time I click a divider, it opens or closes the respective panel below the divider. All this was done by extending the LayoutManager class (not LayoutManager2) and a little bit of special behavior.

What I need to do now is be able to grab a divider and drag up or down, to resize the view of panel . I don't see this being drag and drop (using a TransferHandler) as the view must update with each pixel move.

I have read some about drag gestures, etc but am not sure which way I should be looking . Can someone provide some guidance as to what methods I should be looking at to make this happen and the best way to propagate the event to the layout manager so that it is the one doing the work of the update, as it should be? Should I be looking at Drag gestures, mouse moves, etc...

Thank you for your suggestions.
12 years ago
I have a JScrollPane that at one point in the program can exist inside a JTabbedPane and at other times, exist inside of a JDialog - it gets moved based on user action. I don't know where it is at any given time, I can just get a handle to it (the it being a JScrollPane)

I want to be able to bring whatever the JScrollPane is in, to the front (gain focus??) so the user sees it when some other event occurs. So if it is in a JDialog, I want the dialog to come in front of everything (using modal dialog not an option.) If it is in the JTabbedPane, I want that tab to become selected.

1) How do I tell what the component is currently in (JTabbedPane or JDialog) programmatically and get a proper reference so that I can tell it to gain the focus?

2) What is the best way to "bring it to the front/ gain focus? I know I can use setSelectedCompenent from JTabbedPane and I am not sure on JDialog.

Thanks.
12 years ago
Brian,

That did the trick and I don't see anyway to have figured that out from the docs unless one is intimately familiar with the implementation - that stuff could really be documented better.

13 years ago
Oops - in my above statement I am actually asking the table (as the code shows) and not the model to get the model index from the view index.
13 years ago
I am not doing what I may have led you to believe I am doing. I am asking the model:"For view index of 4, what is the model index associated with that?" - it tells me "oh yes, that is index 6 in the model." When I ask for the column at that index, it says "hold the phone jack, ain't no column there."

Here is the code:

// determine column number in model - different from view if columns in view were moved or changed.
int modelColumnNum = component.getTable().convertColumnIndexToModel(viewColumnNum); // NOTE: viewColumnNum is 4 in my example.
System.out.println(viewColumnNum + ":" + modelColumnNum); // prints "4:6"

TableColumnModel tableModel = component.getTable().getColumnModel();
TableColumn column = tableModel.getColumn(modelColumnNum); // ***exception thrown here *****
String columnName = column.getHeaderValue().toString();


So, is the TableModel.getColumn(index) method asking for the view index, or the model index? I would think it wants the model index. Am I off here? The docs don't explicitly say.
13 years ago
I do get 6 back - then when I ask the model itself to provide the column based on that index (a TableColumn object,) it gives me the exception. So somewhere it thinks there is something at index 6 and somewhere it thinks there is nothing there. The model appears to be out of sync internally.
13 years ago
All,

I have code working (sorta) that allows me to add/remove a column from the model and I see the column disappear or reappear in the table. The model appears to be getting confused about column indexes.

For example, I have these columns:

View Index: 0 1 2 3 4 5 6
Model Index: 0 1 2 3 4 5 6

I tell the model to remove view columns 4 and 5 (yes, I am converting to proper model index before removing). Here is what it looks like now:

View Index: 0 1 2 3 4
Model Index: 0 1 2 3 6

When I convert the view index to the model index for view column "4" I get back 6. When I attempt to retrieve this column using model.getColumn(), I get an array out of bounds exception stating that 6 >= 5 (where 5 I think is the number of columns in the model.) It doesn't appear to be adjusting the index of columns higher up in the array after the remove.

To do the remove, I am calling: table.getColumnModel().remove(column) where column is the actual column object. I store this object in a hashmap elsewhere so I can add it back later.

Is there something I need to call to tell the model to fix itself after doing the remove?

Thanks
13 years ago