How to catch change cell selection in a JTable?

I'm using a ListSelectionListener with a JTable to catch the list selection changes but it only detects row changes, and if i select a different cell but within the same row it does not trigger the event.
Do you guys know a way to detect this event?
Thanks!!!

I'm using a ListSelectionListener with a JTable to catch the list selection changes but it only detects row changes,Try adding a listener for the columns as well:
table.getTableHeader().getColumnModel().getSelectionModel().addListSelectionListener(...);

Similar Messages

  • How can I change (or select) what is being being used when I share, as the file cover. When I Share lets say "Master File" i want to select a frame that is used as the file cover. So when its on my desktop I see this image as the file icon.

    How can I change (or select) what is being being used when I share, as the file cover. When I Share lets say "Master File" i want to select a frame that is used as the file cover. So when its on my desktop I see this image as the file icon.

    I don't think Finder does this (I've tried).
    iTunes does though. Where you can set artwork or the "poster frame"...
    This may not be what you want but if it helps, I know 2 ways  do this is
    Open the video in QuicktimePlayer7 | View | Set Poster Frame (even then, you might need to save it as .mov (ie in a 'mov container').
    Drag the file into iTunes and set the artwork (as in http://www.dummies.com/how-to/content/adding-album-cover-art-or-images-in-itunes .html)
    From there, iTunes will use that frame as the "poster frame" ie the photo/frame that shows when you browse your videos. Which is what you want, but limited to iTunes.
    When I do either of these above, the frame I set does not show when exploring files in "Finder" (or in the other Explorer tool I use called "Pathfinder").
    So it maybe, that exactly what you want, is not possible.

  • How to get the default selection color from JTable

    Hi, there,
    I have a question for how to get the default selection color from JTable. I am currently implementing the customized table cell renderer, but I do want to set the selection color in the table exactly the same of default table cell renderer. The JTable.getSelectionBackgroup() did not works for me, it returned dark blue which made the text in the table unreadable. Anyone know how to get the window's default selection color?
    Thanks,
    -Jenny

    The windows default selection color is dark blue. Try selecting any text on this page. The difference is that the text gets changed to a white font so you can actually see the text.
    If you don't like the default colors that Java uses then use the UIManager to change the defaults. The following program shows all the properties controlled by the UIManager:
    http://www.discoverteenergy.com/files/ShowUIDefaults.java
    Any of the properties can be changed for the entire application by using:
    UIManager.put( "propertyName", value );

  • How do i change the cursor on a jtable header when clicked for sorting?

    here is my question, how do i change the cursor on a jtable header when I click the header for sorting?
    I think it is suppose to be in the fragment of code where the header listener is implemented for sorting, but I'm not quite sure what is the exact component that holds everything so that i can change the cursor...
    below is what I've tried, but it doesn't seem to work... thank you
    public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new
    MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    TableColumnModel columnModel =
    tableView.getColumnModel();
    int viewColumn =
    columnModel.getColumnIndexAtX(e.getX());
    int column =
    tableView.convertColumnIndexToModel
    (viewColumn);
    System.out.println("column = "+column);
    if (e.getClickCount() == 1 && column != -1) {
    System.out.println("Sorting ...");
    Cursor oldCursor =
    tableView.getRootPane().getCursor();
    System.out.println("oldCursor.getType()
    = "+oldCursor.getType());
    if (oldCursor.getType() !=
    Cursor.WAIT_CURSOR){
    JComponent parentPane =
    tableView.getRootPane();
    parentPane.getContentPane().setCursor
    (new Cursor(Cursor.WAIT_CURSOR));
    parentPane.setCursor(new Cursor
    (Cursor.WAIT_CURSOR));
    Cursor newCursor =
    parentPane.getCursor();
    System.out.println("newCursor.getType
    () = "+newCursor.getType());
    int shiftPressed = e.getModifiers(
    &InputEvent.SHIFT_MASK;
    boolean ascending = (shiftPressed == 0);
    //System.out.println("tableView.getRootPane()
    is "+tableView.getRootPane().getRootPane());
    sorter.sortByColumn(column, ascending);
    tableView.getRootPane().setCursor(new Cursor
    (Cursor.DEFAULT_CURSOR));
    //System.out.println("Done sorting");
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
    }

    Hi,
    Try setting the cursor for the table header.
    table.getHeader().setCursor(Wait_Cursor);
    Bala.

  • How do i change the color of a JTable's column names

    hai,
    i'm very new to java and trying to customize the look of a JTable.
    how do i change the color of a JTable's Column names. i know its very simple, i just couldn't figure out how to do it!!
    thanx in advance

    table.getTableHeader().setForeground(Color.RED);

  • (simple q) how do I change the font in a JTable column header?  thanks

    how do I change the font in a JTable column header?
    thanks

    JTableHeader header = yourTable.getTableHeader();
    // Set to serif, bold, size 12...
    header.setFont( new java.awt.Font( "serif", 1, 12 ) );
    // you can set others like color and border, too.
    header.setBackground(Color.white);
    header.setBorder( new EmptyBorder(15,2,15,2) );

  • How to listen for cell selection changes within a JTable

    Problem: my table has 8 columns, with 4 of them containing very large text (up to 1000 chars). Solution is to set the initial size these columns so that the 1st 20 chars are visible, and if one of these columns gains focus/selection via mouse-clicking/tabbing/arrow keys, the entire text is shown in a JTextArea below the table.
    I added a ListSelectionListener to the table, but this only informs me when the row selection has changed.
    I added a FocusListener to the table, but this only informs me when the table gains/loses focus, not when it's been changed within.
    I added a TableColumnModelListener to the TableColumnModel, but this only informs me when the column selection has changed.
    I didn't bother with MouseListener as this won't handle change of selection via tabbing.
    The LSL got me half way there, and the TCML got me the other half. Any ideas on how to combine?
    Or is there something obvious that I'm missing?

    Walter Laan wrote:
    Use both and call the same method which updates the text area based on the current selected (or focused == lead selection index) cell.Yeah - that's what I figured. I just didn't know if there was a magic bullet (i.e., a single listener) out there that I was missing.
    While you are at it, also add a table model listener which calls the same method if the selected cell is updated.I'll keep that in mind, but it's not necessary in this particular case. The table cells in question will be uneditable. The text area will have supporting Edit/Save/Cancel buttons.

  • In the Menu Bar, under File, then Open File, how do I change the selections?

    I have Firefox 11.0 and Windows 5.1 (2007). In Firefox, I click on FILE in the Menu Bar, then OPEN FILE (Ctrl+O), and I see a small box; it says Look in: Mozilla Firefox. Below is a selection of files within the folder Mozilla Firefox. To the left is a column of four other folders: Downloads, My Computer, John, Lori. The last two are obviously two of the folders I've created on my computer, using Windows. But I don't know how they got here! I have no recollection of customizing this particular Firefox menu option by adding those folders, nor can I figure out what to do in order to further customize it. Can anyone tell me: (1) how can I change the original "Look in" option so that it opens with something other than "Mozilla Firefox" (which, after all, I never need to access)? (2) how can I add/delete/change the choices offered in the column on the left, so that different folders are listed? (Currently, if I want to access my Windows folders/files, I first have to minimize the Firefox screen; this seems to me a nice shortcut, but I'd like it to include shortcuts to the folders I use the most, which does not include "Mozilla Firefox"!) (3) Is this actually a Firefox feature, or is it a Windows feature? It does look like Windows (Windows style, Windows folders), but it appears only in the Firefox Menu Bar, along with Bookmarks, Tools, etc. Thanks!

    This sounds like a Windows thing ( You can post a photo and I can tell you for certain). Those folders are Windows system created folders that your computer has had since it was installed, all Firefox does is use the Windows File picker, which is what you see when you open that window. So, to customize you'd have to do that from Windows Explorer (not Firefox).
    The Window should however remember what folder you were in last.

  • How to restrict the cell selection in JTable based on cell contents...

    Hi all,
    I have some problem related to table cell selection.
    I have a table that represets the calendar of some month and year.
    I have the restriction that at one time only one cell could be selected.
    Now i want the cell seletion like this,
    I want only those dates to be selected if that date is after 'today'.
    that is I want to restrict the selection of previous dates.
    how can i do this.
    I have overridden the table methods like this, still no use.
    table = new JTable(model) {
    setOpaque(false);
    setSurrendersFocusOnKeystroke(false);
    setRowHeight(20);
    JTableHeader header = getTableHeader();
    header.setOpaque(false);
    getTableHeader().setReorderingAllowed(false);
    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    getTableHeader().setResizingAllowed(false);
    setCellSelectionEnabled(true);
    setFocusable(true);
    setBackground(new Color(247, 251, 255));
    setFont(newFont);
    public boolean isCellEditable(int row, int col) {
    return false;
    public boolean isCellSelected(int row, int col) {
    int r = getSelectedRow();
    int c = getSelectedColumn();
    String val = (String)getValueAt(r,c);
    Calendar cal = Calendar.getInstance();
    cal.set(currentYear+1900, month,Integer.parseInt(val));
    Date d = cal.getTime();
    Date currentDate = new Date();
    if (d.before(currentDate)) {
         return false;
    } else {
         return true;
    Someone please help...
    -Soni

    Try overriding the changeSelection(....) method of JTable.
    public void changeSelection(int row, int column, boolean toggle, boolean extend)
         if (d.after(currentDate)
              super.changeSelection(row, column, toggle, extend);
    }

  • How can I change the 'selected' color of one JToggleButton only.

    Hi,
    This seems like a simple / trivial question, but I just can't figure it out. Is there a way that I can create a JToggleButton and change the selected color of only that JToggleButton.
    I'm trying to create a simple sidebar like component for navigation within my app. A group of JToggleButton[s] added to a ButtonGroup (with the proper layout / sizing) works great, but the default JToggleButton colors don't suit my needs. I know that I can change the colors using the UIManager / UIDefaults, but I don't want to change the defaults for every JToggleButton in my app. I only want to change the defaults for a few select JToggleButton[s].
    For example, I can do this:
    UIManager.put("ToggleButton.select", UIManager.getColor("Table.selectionBackground"));
    UIManager.put("ToggleButton.background", UIManager.getColor("Table.background"));but I'd rather do something like this:
    JToggleButton jtb = new JToggleButton("Toggle Button Text");
    jtb.setSelectedColor(UIManager.getColor("Table.selectionBackground"));
    jtb.setBackground(UIManager.getColor("Table.background"));The only thing is, I can't find any method that is the equivilant of 'setSelectedColor(Color)' for JToggleButton.
    I know I could do it by adding some listeners to the JToggleButton[s], but that seems a little complicated for something like changing a color.
    I'd also seen a solution in the forums where someone had extended the ButtonUI of the pluggable look and feel they were using. I'm not interested in modifying the look and feel I'm using. As far as I'm concerned, that would defeat the purpose of having a pluggable look and feel as I would have to duplicate my efforts for every look and feel I want to use.
    Any help would be appreciated,
    Ryan

    try this
    import javax.swing.*;
    import java.awt.*;
    class Testing extends JFrame
      public Testing()
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(250,75);
        setLocation(400,300);
        JPanel jp = new JPanel();
        JToggleButton jtb = new JToggleButton("Toggle me");
        jtb.setUI(new MyUI());
        jp.add(jtb);
        getContentPane().add(jp);
      public static void main(String args[]){new Testing().setVisible(true);}
    class MyUI extends javax.swing.plaf.metal.MetalToggleButtonUI
      public Color getSelectColor(){return Color.BLACK;}
    }

  • How to do Multi Cell Selection in JTable

    Dear Friends,
    Any body know Multi cell selection in jtable......
    Thanks

    Try overriding the changeSelection(....) method of JTable.
    public void changeSelection(int row, int column, boolean toggle, boolean extend)
         if (d.after(currentDate)
              super.changeSelection(row, column, toggle, extend);
    }

  • How to catch changed column values in alv oops using grid

    My requirement needs to catch changed column values in alv oops using grid .any method to do this.
    please help me out ,
    Tks in advance

    Have a look into the SAP standarad Programs those programs have the edit option on the ALV output.
    BCALV_EDIT_01
    BCALV_EDIT_02
    BCALV_EDIT_10.
    Regards,
    Gopi ,
    Reward points if helpfull.

  • Change cell's color in jtable when user clicks on it

    Hi everyone,
    i've got a JTable, and would like to change the background of a cell when user selects it
    so i added a mouselistener over my jtable, the mousereleased method looks like this:
              public void mouseReleased(MouseEvent e) {
                   int row = table.rowAtPoint(e.getPoint());
                   int column = table.columnAtPoint(e.getPoint());
                            // help needed
              }as you see, i found the code to get the index of the cell selected, but i don't find any method in JTable class to get the cell component itself, and to alter its background color
    Please notice that the "setSelectionBackground()" in JTable isn't enough, since i would also like to change the color of cells which are not selected when the user select a cell
    how could i do that?
    Thanks in advance!
    edit: i tried the following but it does not work either
              public void mouseReleased(MouseEvent e) {
                   int row = table.rowAtPoint(e.getPoint());
                   int column = table.columnAtPoint(e.getPoint());
                   AbstractTableModel atm = (AbstractTableModel) table.getModel();
                   Component cell = table.getDefaultRenderer(CaseMemoire.class).
                   getTableCellRendererComponent(table, atm.getValueAt(row, column), true, true, row, column);
                   cell.setBackground(Color.MAGENTA);
                   table.updateUI();
              }

    ok i found how to do it
    i directly inserted this in the renderer code:
    if (row == table.getSelectedRow() && column == table.getSelectedColumn())
    cell.setBackground(etc);
    (curiously it does not work with "if (isSelected)")
    thanks :)

  • How to catch the mouse event from the JTable cell of  the DefaultCellEditor

    Hi, my problem is:
    I have a JTable with the cells of DefaultCellEditor(JComboBox) and added the mouse listener to JTable. I can catch the mouse event from any editor cell when this cell didn't be focused. However, when I click the editor to select one JComboBox element, all the mouse events were intercepted by the editor.
    So, how can I catch the mouse event in this case? In other word, even if I do the operation over the editor, I also need to catch the cursor position.
    Any idea will be highly appreciated!
    Thanks in advance!

    Hi, bbritta,
    Thanks very much for your help. Really, your code could run well, but my case is to catch the JComboBox event. So, when I change the JTextField as JComboBox, it still fail to catch the event. The following is my code. Could you give me any other suggestion?
    Also, any one has a good idea for my problem? I look forward to the right solution to this problem.
    Thanks.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test3
    extends JFrame {
    // JTextField jtf = new JTextField();
    Object[] as = {"aa","bb","cc","dd"};
    JComboBox box = new JComboBox(as);
    public Test3() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    String[] head = {
    "One", "Two", "Three"};
    String[][] data = {
    "R1-C1", "R1-C2", "R1-C3"}
    "R2-C1", "R2-C2", "R2-C3"}
    JTable jt = new JTable(data, head);
    box.addMouseListener(new MouseAdapter() {
    // jtf.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JComboBox mouseclick....");
    jt.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JTable mouseclick....");
    // jt.setDefaultEditor(Object.class, new DefaultCellEditor(jtf));
    jt.setDefaultEditor(Object.class, new DefaultCellEditor(box));
    content.add(new JScrollPane(jt), BorderLayout.CENTER);
    setSize(300, 300);
    public static void main(String[] args) {
    new Test3().setVisible(true);
    }

  • How do I change the selected text of a combobox on the fly?

    Hi all,
    I am trying to make a combobox, that is sort of a "recently used" connection box. So you can type in a computer name, hit connect and it then connects. When you disconnect, it adds the computer name, and the logged in username to the combobox,
    so when you click on the drop down, you get selections for example : "COMPUTER1 - johnsmith"
    Which is cool, but what I want, is to be able to click on the selection, and it only puts the computer name in the TextBox - i.e. "COMPUTER1"
    So I have done a bit of research, and tried making a hashtable, and using the DisplayMember and ValueMember properties, so i can at least have a combobox selection like "COMPUTER1 (johnsmith)". I have tried many different pages and suggestions,
    but the furtherest I have got is to only have one or the other value display, or it displays as System.Collection...... (can't remember the rest).
    So my next attempt, is using an event handler for the combobox to change the text, so that once "COMPUTER1 - johnsmith" is selected from the combobox, it puts "COMPUTER1" as the selected text.
    I have tried the following using the SelectedIndexChanged handler. Here is a snippet of my code relating to the ComboBox:
    # PC Connection Input Box$global:pcInputBox = New-Object System.Windows.Forms.ComboBox
    $global:pcInputBox.Location = New-Object System.Drawing.Size(70,50)
    $global:pcInputBox.Size = New-Object System.Drawing.Size(210,20)
    $global:pcInputBox_SelectedIndexChanged = {
    if (($global:pcInputBox.Text -ne $null) -and ($global:pcInputBox.Text -ne "")){
    $selection = $global:pcInputBox.Text
    addLog("Selection is $selection")
    $global:trimSelection = $selection.substring(0,$selection.indexof("-"))
    addLog("TrimSelection is $global:trimSelection")
    $global:pcInputBox.SelectedItem = $global:trimSelection
    addLog("SelectedText is $global:pcInputBox.SelectedItem")
    $global:pcInputBox.add_GotFocus({
    $Form.AcceptButton = $pcButton
    $global:pcInputBox.add_SelectedIndexChanged($global:pcInputBox_SelectedIndexChanged)
    $Form.Controls.Add($global:pcInputBox)
    I have also tried setting the $global:pcInputBox.Text but the result is that nothing changes. Its as though I can't change that ComboBox from its own event?? If I try setting $global:pcInputBox.Text from another function, it will do it fine.
    Can anyone please recommend how I would get this achieved?
    Thanks in advance
    Adam Street

    Use objects:
    $o=@()
    $o+=New-Object PsObject -Property @{Computer='COMP1';User='USER01'}
    $o+=New-Object PsObject -Property @{Computer='COMP2';User='USER02'}
    $o+=New-Object PsObject -Property @{Computer='COMP3';User='USER03'}
    $combobox1.DataSource=[collections.arraylist]($o|select Computer,User, @{N='DisplayName';E={"$($_.Computer)-$($_.User)"}})
    $combobox1.DisplayMember='DisplayName'
    This can also be loaded from a CSV or from AD or almost anywhere else;
    Here is another trivial example:
    $o=@()
    $o+=New-Object PsObject -Property @{Computer='COMP1';User='USER01'}
    $o+=New-Object PsObject -Property @{Computer='COMP2';User='USER02'}
    $o+=New-Object PsObject -Property @{Computer='COMP3';User='USER03'}
    Add-Type -AssemblyName System.Windows.Forms
    $form=New-Object System.Windows.Forms.Form
    $form.StartPosition='CenterScreen'
    $combobox1 = New-Object System.Windows.Forms.ComboBox
    $combobox1.Location='70,50'
    $combobox1.Size='210,20'
    $combobox1.DataSource=[collections.arraylist]($o|select Computer,User, @{N='DisplayName';E={"$($_.Computer)-$($_.User)"}})
    $combobox1.DisplayMember='DisplayName'
    $combobox1.add_SelectedIndexChanged({[System.Windows.Forms.MessageBox]::Show($combobox1.SelectedItem.Computer)})
    $form.Controls.Add($combobox1)
    $form.ShowDialog()
    ¯\_(ツ)_/¯

Maybe you are looking for