JTable with custom cell for folding and unfolding rows

Hi,
I am trying to implement a JTable, whereas one of the columns is a custom component, which has a small + in the right upper corner.
When you push this + the JTable should unfold other rows, giving more detail on the current row.
So something like this :
|--------------------------------|
|   <some-string>              + |
|--------------------------------|Drawing this custom component for the column is no problem but I am having trouble implementing the MouseMotionListener events over this.
If I add a mouseMotionListener to the JTable, I am able to forward these events to my custom class which draws this custom component.
But off course the X and Y coordinates of this MouseEvent are not mapped into the grid of my custom component, which poses my question.
How can I attach to each cell of this custom column of my JTable, a listener as to implement some mouseover and mouseclick stuff ?
In case this post is not all that clear, I will try to add a demo showing my problem.
Kind regards,
Wim.

You're reinventing a wheel that's been done a few times. One example is JTreeTable (http://community.java.net/javadesktop/) but there are others.

Similar Messages

  • Size of combobox in JTable with custom cell editor

    Hi All -
    I have a JTable that displays a combobox in certain cells. I have a custom table model, renderer, and editor. All of that works fine. I render the combobox with the renderer, and then return the combobox as an editor in the editor so that it can drop down and actually be of use. My problem is - I set the size of the combobox with a setBounds call in the renderer, I add it to a panel, and return the panel - because I dont want the combobox to take up the entire space of the cell. This approach fails in the editor. The setBounds and setSize calls have no effect. As soon as you click the combobox, the editor takes over and all of a sudden the combobox resizes to the entire area of the cell. I assume this is because in the editor you arent actually placing anything - your simply returning the "editing form" of the component.
    So - anybody know of a way to work around this? Worst case, I could just allow the combobox to use the entire area of the cell - but it makes it uglier so I figured I would run it by the forums.
    Eric

    Rather than just redirect you to my previous answer from ages ago, I'll just give it again. :-)
    You can actually do this, but you have to get tricky. By default, the dropdown's width will be the same width as the cell... but it doesn't have to be that way. Essentially what you have to do is override the UI (MetalComboBoxUI) for the combo component. In your new customized UI component subclass (that you set the combo to use), modify the the createPopup() method of this UI class, and add your own logic to set the size of the popup before you return it.
    Ideally the size would be based on the computed max width of a rendered item shown in the combo, but really you could set it to whatever just to see how it works.

  • Problem sorting JTable with custom cell editor

    Greetings,
    I have created a JTable with a JComboBox as the cell editor for the first column. However, I couldn't simply set the default cell editor for the column to be a JComboBox, since the values within the list were different for each row. So instead, I implemented a custom cell editor that is basically just a hashtable of cell editors that allows you to have a different editor for each row in the table (based on the ideas in the EachRowEditor I've seen in some FAQs - see the code below). I also used a custom table model that is essentially like the JDBCAdapter in the Java examples that populates the table with a query to a database.
    The problem comes when I try to sort the table using the TableSorter and TableMap classes recommended in the Java Tutorials on JTables. All of the static (uneditable) columns in the JTable sort fine, but the custom cell editor column doesn't sort at all. I think that the problem is that the hashtable storing the cell editors never gets re-ordered, but I can't see a simple way to do that (how to know the old row index verses the new row index after a sort). I think that I could implement this manually, if I knew the old/new indexes...
    Here's the code I use to create the JTable:
    // Create the Table Model
    modelCRM = new ContactTableModel();
    // Create the Table Sorter
    sorterCRM = new TableSorter(modelCRM);
    // Create the table
    tblCRM = new JTable(sorterCRM);
    // Add the event listener for the sorter
    sorterCRM.addMouseListenerToHeaderInTable(tblCRM);
    Then, I populate the column for the custom cell editor like this:
    // Add the combo box for editing company
    TableColumn matchColumn = getTable().getColumn("Match");
    RowCellEditor rowEditor = new RowCellEditor();
    // loop through and build the combobox for each row
    for (int i = 0; i < getTable().getRowCount(); i++) {
    JComboBox cb = new JComboBox();
    cb.addItem("New");
    //... code to populate the combo box (removed for clarity)
    rowEditor.add(i,new DefaultCellEditor(cb, i))); //TF
    } // end for
    matchColumn.setCellEditor(rowEditor);
    Any ideas how to do this, or is there a better way to either sort the JTable or use a combobox with different values for each row? Please let me know if more code would help make this clearer...
    Thanks,
    Ted
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    public class RowCellEditor implements TableCellEditor
    protected Hashtable editors;
    protected TableCellEditor editor, defaultEditor;
    public RowCellEditor()
    editors = new Hashtable();
    defaultEditor = new DefaultCellEditor(new JTextField());
    public void add(int row, TableCellEditor editor)
    editors.put(new Integer(row), editor);
    public Component getTableCellEditorComponent(JTable table,
    Object value,
    boolean isSelected,
    int row,
    int column)
    editor = (TableCellEditor) editors.get(new Integer(row));
    if (editor == null)
    editor = defaultEditor;
    return editor.getTableCellEditorComponent(table,
    value,
    isSelected,
    row,
    column);
    public Object getCellEditorValue() {
    return editor.getCellEditorValue();
    public boolean stopCellEditing() {
    return editor.stopCellEditing();
    public void cancelCellEditing() {
    editor.cancelCellEditing();
    public boolean isCellEditable(EventObject anEvent) {
    return true; //TF
    //return editor.isCellEditable(anEvent);
    public void addCellEditorListener(CellEditorListener l) {
    editor.addCellEditorListener(l);
    public void removeCellEditorListener(CellEditorListener l) {
    editor.removeCellEditorListener(l);
    public boolean shouldSelectCell(EventObject anEvent) {
    return editor.shouldSelectCell(anEvent);
    -------------------

    Well, I found a solution in another post
    (see http://forum.java.sun.com/thread.jsp?forum=57&thread=175984&message=953833#955064 for more details).
    Basically, I use the table sorter to translate the row index for the hashtable of my custom cell editors. I did this by adding this method to the sorter:
    // This method is used to get the correct row for the custom cell
    // editor (after the table has been sorted)
    public int translateRow(int sortedRowIndex)
    checkModel();
    return indexes[sortedRowIndex];
    } // end translateRow()
    Then, when I create the custom cell editor, I pass in a reference to the sorter so that when the getTableCellEditorComponent() method is called I can translate the row to the newly sorted row before returning the editor from the hashtable.

  • How to print jTable with custom header and footer....

    Hello all,
    I'm trying to print a jTable with custom header and footer.But
    jTable1.print(PrintMode,headerFormat,footerFormat,showPrintDialog,attr,interactive)
    does not allow multi line header and footer. I read in a chat that we can make custom header and footer and wrap the printable with that of the jTable. How can we do that..
    Here's the instruction on the chat...
    Shannon Hickey: While the default Header and Footer support in the JTable printing won't do exactly what you're looking for, there is a straight-forward approach. You can turn off the default header/footer and then wrap JTable's printable inside another Printable. This wrapper printable would then render your custom data, and then adjust the size given to the wrapped printable
    But how can i wrap the jTable's Printable with the custom header and footer.
    Thanks in advance,

    I also once hoped for an easy way to modify a table's header and footer, but found no way.
    Yet it is possible.

  • How to create custom infotype for training and event management

    hai freinds can any one tell me how to create custom infotype for training and event managment with following fields
    PS No – PA0000-> PERNR
    Name   - PA0001 -> ENAME
    IS PS.No. – PA0001-> PS no. of Immediate Superior
    IS name PA0001 -> ENAME
    thanx in advance
    afzal

    Hi,
    Your question is not clear for me. Since it is a TEM infotype, it could be a PD infotype.
    If you wish to create a PD infotype, use transaction PPCI to create the infotype.
    But before that you need to create a structure HRInnnn (where nnnn is the infotype number) with all the fields relevant for the infotype.
    If you wish to create a PA infotype, use transaction PM01 to create the infotype.
    But before that you may be required to create a strcuture PSnnnn  (where nnnn is the infotype number) with all the fields relevant for the infotype.
    Regards,
    Srini

  • I have the new macbook pro with retina and I am trying to back up with wd passport for mac and is telling me it is going to take 7days

    I have the new macbook pro with retina and I am trying to back it up, with wd passport for mac and is telling me it is going to take 7days. Any Ideas? Im afraid that means there is something wrong with my hard drive. I have verified the disk and it says everthing is ok.

    It seems to be a common problem that those drives don't perform well, at least not with Time Machine.
    If you have more than one user account, these instructions must be carried out as an administrator.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left.
    Enter the word "Starting" (without the quotes) in the String Matching text field. You should now see log messages with the words "Starting * backup," where * represents any of the words "automatic," "manual," or "standard." Note the timestamp of the last such message. Clear the text field and scroll back in the log to that time. Post the messages timestamped from then until the end of the backup, or the end of the log if that's not clear.
    Post the log text, please, not a screenshot. If there are runs of repeated messages, post only one example of each. Don't post many repetitions of the same message.
    When posting a log extract, be selective. Don't post more than is requested.
    Please do not indiscriminately dump thousands of lines from the log into a message.
    Some personal information, such as the names of your files, may be included — edit that out, too, but don’t remove the context.

  • To build some Custom reports for Sales and Distribution

    I want to build some Custom reports for Sales and Distribution.
    I do not know how to do that.
    I reviewed lots of threads earlier, but couldnt understand how to do that.
    If any one can send me suitable step by step guide, I will really appreciate it.
    Or send me some link or some documents with couple of nice exampples of how to do that.
    Which setting to make in B  ex and everything.
    I am new to BI.
    Please advise.
    Points will be awarded

    Hi,
    Could you be more specific about your requirement. I could understand that you wanted to know what all are the Customer sales reports could be provided in SD.
    Generally irrespective of projects few reports are considered as baseline reports for any SAP implementations.
    For example: 1. Order intakes daily
                          2. Order intakes monthly
                          3. Order magin (daily,monthly)
                         4. Order analysis.
    Best regards.

  • Make Record for folder and multi-selected files

    Hi,
    'Make Record' item disappeared in MENU for folders not for files.
    And it can't make record for multi-selected files.
    I can only make Record by one and one.
    How to make Records for folder and multi-selected files?
    Regards
    Kitae

    Programatically, only a single document at a time can be made a record :-
    makeRecord
    public Item makeRecord(long parentId,
    long docId,
    NamedValue[] attrs,
    AttributeRequest[] attributes)
    throws FdkException
    You could potentially through a custom workflow triggered on UserRequest allow multiple submitted documents to be made records through a custom BPEL process calling Content DB Web Services.
    Matt.

  • How do I switch my email account to cell for FaceTime and iMessage

    How do I switch my email account to cell for FaceTime and iMessages?

    I think you are asking how to use your phone number with FaceTime and Messages rather than an email address, but you must have an iPhone number not just any "cell" phone number.
    Take a look at this.
    iOS and OS X: Link your phone number and Apple ID for use with FaceTime and iMessage

  • I have 2 macbooks each with an account for me and one for my wife. I use one Macbook logged in with my account and my wife uses the other Macbook only loged in on her account. We both make regular time-machine back-ups each on a separate external disk

    I have 2 Macbooks each with an account for me and one for my wife. I use one Macbook logged in with my account and my wife uses the other Macbook only logged in on her account. We both make regular time-machine back-ups each on a separate external disk. Is it possible to update her account on my macbook using her external disk without overwriting my stuff on the same Macbook and vice versa?

    Time Machine does not do individual accounts. It records the complete drive. So if you were to use her TM backup on your Mac it would make your Mac just like hers. Both yours and her account on your MAC.
    Just copy the missing files over from her Mac to yours. If there are differennt programs on each then they would need to be installed on both.

  • Ihave downloaded iCloud to my new PC and am using windows 7 and office 2010. I cannot get iCloud to come up on Outlook with the choices for CalendCar and contacrts, my iMail account is there, but not the general coud choices. What am I doing wrong.

    I have downloaded iCloud to my new PC and am using Windows 7 and Offie 2010. I cannot get iCloud to come up on Outlook with the choices for Calendar and Contacts, my iMail accnt is there***.me.com, but not the general Cloud choices for calendar and contacts? What am I doing wrong?

    I have I cloud 2.0.2.187 loaded just downloaded yesterday.

  • I cant turn on the coockies when i go to the tools --- options--- privacy and choose use custom sitting for history and click OK. Then o go back nothing changed

    i cant turn on the coockies when i go to the tools --->options--->privacy and choose use custom sitting for history and click OK. Then o go back nothing changed

    Note that the "Use custom settings for history" selection allows to see the current history and cookie settings, but selecting this doesn't make any changes to history and cookie settings.<br />
    Firefox shows the "Use custom settings for history" selection as an indication that at least one of the history and cookie settings is not the default to make you aware that changes were made.<br />
    If all History settings are default then the custom settings are hidden and you see "Firefox will: (Never) Remember History" (Never remember history means that Private Browsing mode is active).
    "Use custom settings for history" stays selected if at least one of the History or Cookie settings is not the default to make you aware that changes from the defaults are made.
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do not click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    If you do not keep changes after a restart then see:
    *http://kb.mozillazine.org/Preferences_not_saved

  • I have a Honday FIT 2013 with the USB for iPod and the Auxillary jack. I plan to purchase an iPhone 5c. Can I listen to music from my iPhone through my car speakers?

    I have a Honday FIT 2013 with the USB for iPod and the Auxillary jack. I plan to purchase an iPhone 5c. Can I listen to music from my iPhone through my car speakers?

    Click the "Upgrade Eligibility" link on the right side (under "Learn more about buying iPhone) here:
    http://store.apple.com/us/buy-iphone/iphone5s
    If you're not eligible for upgrade, it will tell you how much more than US$199 you will be charged.

  • With my friend for trolling, and I decided I wanted it out of my life, but forgot the password and used a fake email! I have no

    How do I stop getting notifications from the wrong instagram account on my iPhone?
    Okay. So, I made a second instagram account with my friend for trolling, and I decided I wanted it out of my life, but forgot the password and used a fake email! I have no way of logging on or deleting the account, so I figured I would just forget about it. But after I logged back on to my regular one, I kept getting notifications from the fake account!! I don't know what to do because there are some vulgar things that keep popping up and I just want them gone! :'( Can anyone help??

    see this support article about A flashing question mark appears when you start your Mac

  • Issue with Visibility Settings for Backgrounds and Layers

    I am using Acrobat Pro XI 11.0.10 (Windows) and having an issue with visibility settings for layers and backgrounds. I am attempting to get backgrounds to appear while viewing in Adobe Reader and Acrobat Pro but not be printed and so far have had no success.
    When using a background the Appearance Options dialogue has "Show when printing" unchecked, but "Show when displaying on screen" is checked. This results in the background not showing on the screen, and the background will only appear once the box for "Show when printing" is checked. It looks like the option for printing is dictating whether or not the background is able to appear.
    Using layers has not worked either. The background layer is set to "Never Prints", but will still show up when printed.
    I was wondering if anyone else has run into this and has a solution, or has any recommendations.
    Thanks in advance.

    Hi setrev2012,
    How are you adding the backgroud?
    The only way I can think to accomplish this is via a watermark.
    The basics...
    Open PDF in Acrobat. Choose Pages > Watermark > Add Watermark.
    Select a jpg or PDF of your background and adjust scaling options as desired.
    Then click the Appearance Options.. and uncheck the Show When Printing option.
    In this image the PDF is a blank page with the word "Test" on it. The watermark is the stamp and impression (a stock photo jpg).
    If you want a solid color background, just create a flat image of the background color for use as the watermark.
    If you have already followed the steps and still facing the issue then please share the file with me at [email protected] so that i can have a look.
    Regards,
    Rave

Maybe you are looking for