Cross-JTable selection

In a scenario where there are two JTable's in order to implement "locked (frozen) columns", one has to address the cross-JTable selection issue that occurs when both tables' "columnSelection" and "rowSelection" properties are enabled, and the user clicks & drags the mouse to select a range of cells across the two JTables.
Has anyone ever done this?
Mert

Interesting question - I would try to register one mouseListener to both tables that makes sure the events are redispatched if the mouse exits the one and enters the other during a addSelection.Or you can try to patch the BasicTableUI.MouseHandler to go on with addSelection even after a mouseExited during a mouseDragged. Never tried it, though. (Always assuming that one there is one selectionListener that extends a selection in one table to the other)
Greetings
Jeanette

Similar Messages

  • Create cross-client selection variant

    Hi,
    Can anyone please let me know how to create a cross-client selection variant. I am trying to run a report with a default selection variant but will require the variant to be available in all clients. I'm working on an R/3 release 4.6b system.
    Regards,
    Andy.

    Hi,
       Create variant prefixing "CUS&" followed by variant name, this will create a system variant and ask for a TR. the variant thus created will be available in all clients, If not you can just import the Tr created to all client using transaction SCC1.
    Award points if found usefull
    Regards
    Simin.R

  • JTable selection problem with jdk1.5.0_05

    Today I tried the new jdk1.5.0_05 release and noticed with a JTable I can only select a single column and row with the mouse. With jdk1.5.0_05 I could select multiple cols and rows with the mouse. I looking at the listselectionmodel for the jtable i see it is set to mulitple. Is this a bug in the new java 1.5 release?

    Yeah, the .jar files are definitely there and the
    small class I just wrote is in the Classes directory.Yes, but you're calling javac.exe, not some jars. Did you check that javac.exe is there? Stupid question, yes, but I've seen it all...
    I changed the path in Control Panel -> System ->
    Advanced -> Environment Variables. I've also beendoing this is the command prompt:
    set
    CLASSPATH=%CLASSPATH%;C:\Java\jdk1.5.0\bin;C:\Java\Cla
    ssesNo need to add the /bin directory to the classpath, there are no classes in it...

  • Intermittent JTable Selection Problem

    Hi,
    Everyone once in a while, under NT with 1.4.x, I have problems selecting and highlighting row under JTable. It happens a good bit, but this does not happen all the time. When the table is buggy, it does not keep the row selected nor does it highlight the row. You may have the row selected on a mousedown, but once you release the mouse it's done.
    Since this is happening for a variety of JTable's I didn't bother to send Java code. Has anyone else encountered this sort of thing? Or does anyone know what I should be looking at?
    The intermittent part is what's killing me. It makes it hard to track down with any high degreee of confidence in the answers.
    thanks for any input or suggestions,
    Geoff

    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class Test extends JFrame {
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        String[] head = {"One","Two","Three"};
        String[][] data = new String[40][3];
        for (int r=0; r<40; r++) {
          data[r] = new String[3];
          for (int c = 0; c < 3; c++) data[r][c] = "R" + r + "-C" + c;
        content.add(new JScrollPane(new JTable(data,head)));
        setSize(400, 400);
        show();
      public static void main(String args[]) { new Test(); }
    }I've been clicking until my fingers bled. Can't see a problem.

  • JTable select row by double click, single click

    Hi all,
    I would like to double click on the row of the JTable and pop up a window for adding stuff, a single click for selecting the row and then in the menu bar I can choose to etither add, change or delete stuff. I try to use the ListSelectionModel but does not seems to distinguish between double or single click.
    Any idea, doc, samples?
    or I should not use ListselectionModel at all?
    thanks
    andrew

    Hi. I used an inner class. By using MouseAdapter u dont have to implement all methods in the interface..
    MouseListener mouseListener = new MouseAdapter()
    public void mouseClicked(MouseEvent e)
    if(SwingUtilities.isLeftMouseButton(e))// if left mouse button
    if (e.getClickCount() == 2) // if doubleclick
    //do something
    U also need to add mouselistener to the table:
    table.addMouseListener(mouseListener);
    As I said, this is how I did it.. There are probably alot of ways to solve this, as usual :). Hope it helps

  • Overriding Default JTable Selection Behavior

    I'm attempting to override the default selection behavior of a JTable. For clicking, I want the table to behave basically as if the ctrl key was being held down all the time. That works great.
    I want the behavior of dragging a selection to behave a certain way as well. If ctrl is not held down, then a drag should cancel the current selection and start a new one at the drag interval. This works fine too.
    However, if ctrl is held down during a drag, I want the dragged interval to be added to the selection instead of replacing it. This almost works. However, if I hold ctrl while dragging, it no longer let's me "undrag" the selection: once a cell is inside the dragged interval, it's selected, even if you drag back over it to deselect it.
    I understand why that's happening given my approach, but I'm looking for a way around it. Does anybody have any ideas about how to get a JTable to behave the way I want?
    Here's a compilable program that demonstrates what I'm doing:
    import javax.swing.*;
    import java.awt.event.*;
    public class TestTableSelection{
         boolean ctrlDown = false;
         JTable table;
         public TestTableSelection(){
              JFrame frame = new JFrame("Test Table Selection");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //give the table random data
              String [][] data = new String [10][5];
              String [] names = new String [5];
              for(int i = 0; i < 5; i++){
                   names[i] = "C: " + i;
                   for(int j = 0; j < 10; j++){
                        data[j] = "t: " + (int)(Math.random()*100);
              table = new JTable(data, names){
                   //override the default selection behavior
                   public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                        if(ctrlDown){
                             //ctrl + dragging should add the dragged interval to the selection
                             super.changeSelection(rowIndex, columnIndex, toggle, extend);     
                        else{
                             //clicking adds a row to the selection without clearing others
                             //dragging without holding ctrl clears the selection
                             //and starts a new selection at the dragged interval
                             super.changeSelection(rowIndex, columnIndex, !extend, extend);
              //keep track of when ctrl is held down
              table.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent e) {
                        ctrlDown = e.isControlDown();
                   public void keyReleased(KeyEvent e){
                        ctrlDown = e.isControlDown();
              frame.getContentPane().add(new JScrollPane(table));
              frame.setSize(250, 250);
              frame.setVisible(true);
         public static void main(String[] args){
              new TestTableSelection();
    Let me know if any of that isn't clear.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    This change seemed to work for me
              table = new JTable(data, names){
                   int prevRow = -1;
                   //override the default selection behavior
                   public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                        if(ctrlDown){
                             //ctrl + dragging should add the dragged interval to the selection
                             if ( rowIndex != prevRow ) {
                                  prevRow = rowIndex;
                                  super.changeSelection(rowIndex, columnIndex, true, false);
                        else{
                             //clicking adds a row to the selection without clearing others
                             //dragging without holding ctrl clears the selection
                             //and starts a new selection at the dragged interval
                             super.changeSelection(rowIndex, columnIndex, !extend, extend);
              };

  • Jtable selection problems

    I'm trying the following code, but it doesn't work!
    the selection is not set to another row at all in my JTable.
    collectionsTableModel.collections.remove(collectionsTableModel.getCollection(num));
    setNewSelectionInsteadOf(num);
    collectionsTableModel.fireTableDataChanged();
    private void setNewSelectionInsteadOf(int num) {
    int newSelectedRow = num+1>collectionsTableModel.getRowCount() ? num-1: num;
    if (newSelectedRow>=0 && newSelectedRow < collectionsTableModel.getRowCount()) {
    collectionsTable.setRowSelectionInterval(newSelectedRow,newSelectedRow);
    }

    Actually the bug is just here:
    collectionsTable.setRowSelectionInterval(newSelectedRow,newSelectedRow);
    where collectionsTable is my JTable
    and newSelectedRow is an int that set the new selected row.
    it does not set the selected row at all...
    could this be because I do not fire the fireTableDataChanged in the right time?

  • JTable- Selection Color

    Hallo,
    I want to change my border Color of selected Cell. Because I don�t find any possibilty to change this Color.
    I create my Table with my own AbstractTableModel. Till now, I don�t have write my own TableCellRenderer.
    Can you help me?
    Stefan Gabel

    Till now, I don�t have write my own TableCellRenderer.Well, it seems that now you do...
    But watch out from a bug: the isSelected always returns false.
    So you have to do it this way:
            DefaultTableCellRenderer myColumnRenderer = new DefaultTableCellRenderer() {
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    // Correct the selected value, since java has a bug here.
                    int[] iSelectedRows = table.getSelectedRows();
                    if (iSelectedRows != null) {
                        for(int i=0; i< iSelectedRows.length; i++) {
                            if (iSelectedRows[i] == row) {
                                isSelected = true;
                                break;
    ...This handles the rows, add a similar check for columns if you like cell-specific.
    Then just set the color if it is REALLY selected.

  • JTable select problem

    Hello,
    I have a great problem with my JTable. I have a JTable with few lines and two columns. The user can select one line and with the following statements
    int column = tblSearchResults.getSelectedColumn();
    int row = tblSearchResults.getSelectedRow();     
    Object value = tblSearchResults.getValueAt(row,column);
    I retrieve the value with which I display details of a second line in a new window (when the user presses a certain button). The problem is when I close this new window and want to select a new line the getSelectedColumn and the getSelectedRow returns always -1 which says that no line is marked although I have marked a line.
    Does anybody know what the problem can be? - it must concern the open and close of the detail window, because when I omit the code line which opens the detail window and only make System.out.println's with the getSelectedColumn and getSelectedRow it will always output the right line...
    thx
    pat

    Swing related questions should be posted in the Swing forum.
    You have not provided enough information to solve your problem. We don't know how you are invoking the dialog. Are you double clicking on a row, do you have a button the user clicks on to invoke processing?
    So for this, and future postings, you should learn how to create a simple demo program that shows your problem so we don't have to guess what you are doing.

  • Simple JTable / Select Row example?

    Hi - I'm having a really hard time wrapping my brain around JTables and their events. Can anybody give me just a real simple example of how to get the value of whatever cell (row, preferrably) by clicking on that cell / row?

    Hey there,
    im currently doing Jtables within a system i am coding too so thought i would help ya out!
    1. You can recognise if a row is selected within your table by using a possible two methods: example of how this can be implemented:
    //This method used for only one row at a time being selected
    int selectedRow = table.getSelectedRow(); (table being the name of your JTable obviously)
                        if (selectedRow == -1) {//When there is no selected row show error message
                             JOptionPane.showMessageDialog(null, "Must select an employee from the table", "Error Message",
                                                      JOptionPane.ERROR_MESSAGE);
                        else {
                        //DO SOMETHING                    }
                   }2. Or you could use the public int [ ] getSelectedRows() method of recognising selected JTable rows: example of how u might implement this, this returns an array of interger values when 1 or more rows are selected:
    int [ ] rowselected = table.getSelectedRows();
    //In order to go through each selected row and do something with it a loop is obviously needed like:
    for (int i = 0; i < rowselected.length; i++) {
                        String empName = (String)(table.getValueAt(rowselected,0));
                        System.out.println(empName);
    Hope this helps ;-)

  • JTable, select row on right mouse click

    Hi,
    If I right click on a jTable row in my application, the row I click on does not get selected.
    How can I modify the mouse listener attached to the jtable to deal with this?
    jtable.addMouseListener( { e->
    if (e.isPopupTrigger())
        swing.popupMenu(menuItems).show(e.getComponent(), e.getX(), e.getY());
    } as java.awt.event.MouseListener)Thanks!

    Problem solved!
    jtable.addMouseListener( { e->
    if (e.isPopupTrigger()){
        int row = jtable.rowAtPoint( e.getPoint() );
        jtable.changeSelection( row, 0, false, false );
        swing.popupMenu(menuItems).show(e.getComponent(), e.getX(), e.getY());
    } as java.awt.event.MouseListener)

  • Regarding JTable selection

    Hi,
    I did one non-editable JTable. If I press "F2" button on selected row of that table, It's throwing following exception on console. Please try to provide solution for me.
    Regards & Thanks,
    Sukumar
    java.lang.NullPointerException:
    at javax.swing.plaf.basic.BasicTableUI$3.actionPerformed(BasicTableUI.java:675)
    at javax.swing.JComponent.processKeyBinding(JComponent.java, Compiled Code)
    at javax.swing.JComponent.processKeyBindings(JComponent.java, Compiled Code)
    at javax.swing.JComponent.processKeyEvent(JComponent.java, Compiled Code)
    at java.awt.Component.processEvent(Component.java, Compiled Code)
    at java.awt.Container.processEvent(Container.java, Compiled Code)
    at java.awt.Component.dispatchEventImpl(Component.java, Compiled Code)
    at java.awt.Container.dispatchEventImpl(Container.java, Compiled Code)
    at java.awt.Component.dispatchEvent(Component.java, Compiled Code)
    at java.awt.LightweightDispatcher.processKeyEvent(Container.java, Compiled Code)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java, Compiled Code)
    at java.awt.Container.dispatchEventImpl(Container.java, Compiled Code)
    at java.awt.Window.dispatchEventImpl(Window.java, Compiled Code)
    at java.awt.Component.dispatchEvent(Component.java, Compiled Code)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java, Compiled Code)
    at java.awt.EventDispatchThread.pumpOneEventForComponent(EventDispatchThread.java, Compiled Code)
    at java.awt.EventDispatchThread.pumpEventsForComponent(EventDispatchThread.java:95)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:90)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

    A little busy to help people.
    But happy you found my posted message.
    http://forum.java.sun.com/thread.jsp?thread=137174&forum=57&message=1135327
    Still, I do not research how to unregister yet,
    but you can register "null" action.
    Good luck.

  • Limit JTable selection behavior

    I have a simple table with 3 columns an multiple rows. If I select a row with the left mouse button and, with out letting go, move the mouse pointer up to a higher row or down to a lower row the currently selected row changes to the row the mouse pointer is over.
    I need to stop this behavior.
    If I select a row with a left mouse press and move the mouse around when I do a mouse release I want the selected row to still be the one i did the mouse pressed action over.
    Please Help.

    This change seemed to work for me
              table = new JTable(data, names){
                   int prevRow = -1;
                   //override the default selection behavior
                   public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                        if(ctrlDown){
                             //ctrl + dragging should add the dragged interval to the selection
                             if ( rowIndex != prevRow ) {
                                  prevRow = rowIndex;
                                  super.changeSelection(rowIndex, columnIndex, true, false);
                        else{
                             //clicking adds a row to the selection without clearing others
                             //dragging without holding ctrl clears the selection
                             //and starts a new selection at the dragged interval
                             super.changeSelection(rowIndex, columnIndex, !extend, extend);
              };

  • JTable: selecting multiple cells

    Supposing you have a spreadsheet layout with A,B,C on the columns and 1,2,3 on the rows, is it possible to allow the user to select cells A1 and C3, like they can in a normal spreadsheet app?
    Somehow I need to obtain this kind of functionality from our system, although I have no idea how at present.

    Something like.....
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TableExample extends JFrame {
       boolean[][] selectedCells = new boolean[5][5];
        public TableExample() {
           super("Table Selection Test");
           final JTable table = new JTable(5, 5) {
              public boolean isCellSelected(int row, int column) {
                 return selectedCells[row][column];
           table.addMouseListener(new MouseAdapter() {
              public void mousePressed(MouseEvent e) {
                 int row = table.rowAtPoint(e.getPoint());
                 int column = table.columnAtPoint(e.getPoint());
                 if (e.isControlDown()) {
                    selectedCells[row][column] = !selectedCells[row][column];
                 else {
                    for (int i = 0 ; i < 5 ; i++) {
                       for (int j = 0 ; j < 5 ; j++) {
                          selectedCells[i][j] = false;
                    selectedCells[row][column] = true;
                 table.repaint();
          getContentPane().setLayout(new BorderLayout());
          getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(400, 400);
       public static void main(String[] args) {
          new TableExample().setVisible(true);
    }

  • JTable - Selecting selected columns

    Is there a way to select a "selected" number of columns (i.e. not all columns of a row) in JTables?
    The default selection criteria is by rows, I want to be able to select by both rows and columns, something like the excel spreadsheets.
    Thanks.

    Look at some of these
    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    There is one which adds a 'row header'. From there you should be able to select a row with it.

Maybe you are looking for