Changing mouse click behavior on JTable

Hi everybody,
The default behavior of a mouse click on a jTable is selection of the cell.
I would like to change the behavior so when the user clicks once on the cell, the content can be marked and is ready to change. That would give the user the same feeling as Excel.
Is there any way that I can do this without writing a new mouse/event handler?
thanks,

With a call to getSelectionModel() of JTable, you can get a reference to the ListeSelectionModel.
This is in fact an instance of DefaultListSelectionModel, which allows you to set a new listener object using addListSelectionListener(ListSelectionListener l).
All you have to do then is implement a custom ListSelectionListener which handles events as you want.
Unfortunately there isnt going to be a way of avoiding writing a Listener, but this is how you would go about it.
colr__

Similar Messages

  • Changing mouse click text select in term windows

    Minor nit/question -
    When you click on text in the terminal window, it only selects up to a non-word character (i.e. it stops selecting at punctuation, so trying to click on Foo::Bar to select it all, it goes first to Foo (stopped by the ':') and then selects the entire line on the next click.
    Most Linux flavors seem to go by whitespace - first click selects everything that is between whitespace, even if it includes non-alpha characters (thus you get Foo::Bar with one click); then the next click selects the whole line. Having gotten used to that, the Mac behavior is... annoying.
    So - how does one change it? Can it be user-config'd?
    Thanks for any assistance.

    I have actually found out what the issue is. I have called a javascript method onblur of the text element which is present in the suggest region. This onblur method is interfering with the mouse click event of the auto complete suggestions shown. If i remove the onblur method, everything is working fine. I have simulated the issue in the html file present in the compressed folder attached herwith. In that i am actually throwing an alert on blur where as in real scenario i have some other functionalities to be handled on blur.
         For clarity i will explain the real scenario as well. When the user selects a suggestion from the auto complete div, the value will be placed in the text box and on blur of the text box, the dataset will be filtered based on the value in the text box.  Few pointers on this issue:
    The on blur functionality does not interfere when we select a suggestion using down arrow in key board.
    If i use mouse click to select then i have to wait for few milliseconds extra with the mouse clicked on the value before releasing it, so that the selected value is available in the textbox. Within this few milliseconds, the onblur function gets executed and then self.nodeClick is executed thus placing the value in the textbox. But forcing the user to keep the mouse clicked on the value for sometime will not sound good.
         Kindly advise as to how this issue could be handled.

  • How do I change mouse button behavior in firefox to make new mouse shortcuts?

    Hi,
    For some time now I've wondered if it is possible to easily change the default behavior of mouse buttons in Firefox. What I'd like to do is define a new mouse button combination which replicates the function of an already-defined keyboard shortcut. In particular, currently, when one holds down the shift key while left-clicking the mouse while over a link, that link is opened in a new window. What I'd like to do is to have exactly the same behavior occur when I click and hold the left mouse button while pressing and releasing the right mouse button. This then makes opening a link in a new window a menu-less, one-handed operation.
    Anyone have any ideas how this might be done? Thanks!

    Hello,
    Does this addon - https://addons.mozilla.org/en-US/firefox/addon/mousecontrol/ meet your requirement? Also, you can check the list of mouse shortcuts here [[Use mouse shortcuts to perform common tasks in Firefox]]
    Hope this helps.

  • Change mouse button behavior

    I am trying to change the behavior of my mouse buttons, specifically, I want ALT-<Mouse2Click> to f.raise_lower the active window regardless of where (in the active window) the mouse is pressed. Currently, Btn2Click on the frame or title bar exibits this behavior, but not in the window part.
    I have tried adding a line to both my ~/.dt/dtwmrc and to the system dtwmrc file, but neither change seems to have any effect.
    This is the relevant section of my dtwmrc file:
    Buttons DtButtonBindings
    <Btn1Down> root f.marquee_selection
    <Btn2Click> root f.toggle_frontpanel
    <Btn3Down> root f.menu DtRootMenu
    Shift<Btn1Click> frame|icon f.lower
    <Btn1Click> frame|icon f.raise
    <Btn1Click2> frame f.maximize
    <Btn1Click2> icon f.restore
    <Btn2Click> frame|icon f.raise_lower
    <Btn3Down> frame|icon f.post_wmenu
    Alt<Btn1Click> frame|icon|window f.raise
    Alt<Btn1Click2> frame|window f.minimize
    Alt<Btn1Click2> icon f.restore
    Alt<Btn2Click> window f.raise_lower
    Alt<Btn1Down> frame|icon|window f.move
    I added the "Alt<Btn2Click> window f.raise_lower" line.
    Any thoughts? Am I doing it wrong? The CDE docs available online would indicate that this is the correct place to make such a change.
    Thanks,
    Linus

    Hello,
    Does this addon - https://addons.mozilla.org/en-US/firefox/addon/mousecontrol/ meet your requirement? Also, you can check the list of mouse shortcuts here [[Use mouse shortcuts to perform common tasks in Firefox]]
    Hope this helps.

  • Changing mouse click default to "open" (file/folder)

    My logitech mouse button1 defaults to "search" instead of "open' when I left click. i don't want to have to rt click first, then select "open". I want mouse default to be "open". any suggestions?

    Hi,
    I have just had the same problem, but fixed it!
    All I did was go to any folder, Tools, Folder Options, File Types and find "File Folder" in the list
    Then go to Advanced and select New
    Add one for Action - Open and add an application of Explorer.exe
    This sorted it!
    Hope this helps you
    Col

  • Changing Mouse Click Behaviour

    Hi,
    I have a requirement where I am displaying list of LinkToURL elements pointing to some URLs.
    Now I want mouse left click to trigger action of "Save Target As" action. (Normally, this is present in "Right Click --> Save Target As")
    Is there any way in Web Dynpro code (or rather any way) to achieve this?
    Thanks and regards,
    Amey Mogare

    Hi Armin,
    Thank you for reply.
    Yes, FileDownload UI element is the one which will be useful for me.
    This URL which I am talking about is pointing to the file located on some other server on same network.
    So I need to first read byte stream from URL and then convert it to IWDResource?
    I was looking for any method that will help me to achieve this.
    Any idea which code might work?
    Thanks and regards,
    Amey Mogare

  • Error mouse click header on jtable

    I have a small project. I use jtable, i wrote class MymodelTable for jtable (include event mouseclicked).
    On jtable, i can click on header to sort.
    But, when i click button search a string (get from textfield), i was be error ...
    Please help me resolve my error. (I attached my project in path: http://www.mediafire.com/?u4nw7uajdxrg97h )
    Thanks

    With a call to getSelectionModel() of JTable, you can get a reference to the ListeSelectionModel.
    This is in fact an instance of DefaultListSelectionModel, which allows you to set a new listener object using addListSelectionListener(ListSelectionListener l).
    All you have to do then is implement a custom ListSelectionListener which handles events as you want.
    Unfortunately there isnt going to be a way of avoiding writing a Listener, but this is how you would go about it.
    colr__

  • Mouse click behavior

    I have three macs. My new mini behaves a little differently and I want to know what I'm doing wrong. Usually when I click on a folder and drag it down to the desktop it moves by it self (simple normal drag and drop)....But on my mac mini 80% of the time I click on the file and drag it down it begins selecting all the files below it....Im being very careful and clicking specifically on the icon and Ive tried different mice and track pads....Please help as its infuriating......
    Thanks and cheers.

    Is this while you are in a finder window? Does it seem to be only one file you are having the problem with or are there others?

  • How to override Ctrl-Click behavior in Java L&F

    On the Mac, Ctrl-Click is the popup trigger. While Java L&F designers were obviously aware of this (it is warned about in the Java Look and Feel Design Guidelines, 2nd ed, page 106). However, just two pages later (page 108), they then generically specifify that Ctrl-Click is used in lists and tables to toggle the selection.
    The implementation of the Java L&F does not appear to consider the Mac's use of Ctrl-Click and still toggles selection. If there is an additional mouse listener that shows a menu in response to the popup trigger, it will ALSO open the menu on Ctrl-Click.
    What is the best way to overide the Ctrl-Click behavior in JTable etc. to NOT do the toggle selection? Note that this is a mouse event and not a key event, so it can't be turned off or changed by the getActionMap() mechanism.
    Also, does anyone know what the "Command" modifier on the Mac (Command-Click is supposed to toggle selection on Macs) shows up as in the InputEvent (isMetaDown(), isAltGraphDown()...)?

    Try extending the JList and override the processMouseEvent(MouseEvent evt) method and show your popup menu when the user clicks the mouse while holding the CTRL key down. The code below demonstrates the same.
    import java.awt.BorderLayout;
    import java.awt.event.MouseEvent;
    import java.util.Vector;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JOptionPane;
    import javax.swing.JScrollPane;
    import javax.swing.ListModel;
    import javax.swing.WindowConstants;
    public class Temp extends JFrame {
         public Temp() {
              super("Temp");
              setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              String [] items = {"One", "Two", "Three", "Four", "Five"};
              JList list = new MyList(items);
              JScrollPane scroller = new JScrollPane(list);
              getContentPane().add(scroller, BorderLayout.CENTER);
              pack();
              setVisible(true);
         class MyList extends JList {
              public MyList() {
                   super();
              public MyList(Object[] listData) {
                   super(listData);
              public MyList(Vector listData) {
                   super(listData);
              public MyList(ListModel dataModel) {
                   super(dataModel);
              protected void processMouseEvent(MouseEvent evt) {
                   System.out.println(evt.isPopupTrigger());
                   int onmask = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
                   if(evt.getModifiersEx() == onmask) {
                        JOptionPane.showMessageDialog(this, "Control + click");
                   else {
                        super.processMouseEvent(evt);
         public static void main(String[] args) {
              new Temp();
    }Hope this helps
    Sai Pullabhotla

  • Issues with "wait until mouse click"

    when I put wait until mouse click it doesn't register mouse down or mouse up. Because of that, my game is sloppy and skips some scenes if I accidentally hold down my mouse for more than a split-second click. Is there any way to manipulate the wait for mouse click behavior so it works only when the mouse button is released?

    Hmm, I wonder if he figured it out already, since he didn't even answer your question.  He seems to be talking about the built-in "Wait for Mouse Click or Key Press" behavior in the behavior library.  Sometimes those behaviors can become overly complicated for the simplest of things.  I recommend you just go ahead and roll your own frame script, as EtchK was implying.  It's pretty easy, you just need two short handlers:
    on exitFrame
      go to the frame
    end
    on mouseUp
    -- do whatever
    end

  • The answer helped me.But still, what are the settings that I have to change for the behavior of the mouse pointer towards finder? Also the mouse pointer sometimes  doesn't accept my command and start clicking itself.what is the problem and how to fix it?

    The answer helped me.But still, what are the settings that I have to change for the behavior of the mouse pointer towards finder? Also the mouse pointer sometimes  doesn't accept my command and start clicking itself.what is the problem and how to fix it?

    If the mouse clicks something on its own then it looks like you have a hardware problem with the trackpad or possibly the battery that is right underneath the trackpad.
    I have read that the battery can swell and that would put pressure on the trackpad.

  • Mouse click in JTable

    Hi All,
    I want to force mouse click when right clicking on a JTable. I mean when the right click is done in the mouse, the left click should be forced. I have a JTable with some values in it. I want to select the particular column in the table when right click mouse action. How can I do it?
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class TableDemo extends JFrame
        private JTable table;
        private JScrollPane jsp;
        private JPanel jp;
        public TableDemo()
            initComponents();
        private void initComponents()
            jp = new JPanel();
            String columnNames[] = { "Column 1", "Column 2", "Column 3" };
            String dataValues[][] =
                { "12", "234", "67" },
                { "-123", "43", "853" },
                { "93", "89.2", "109" },
                { "279", "9033", "3092" }
            table = new JTable(dataValues, columnNames);
            jsp = new JScrollPane(table);
            jsp.setViewportView(table);
            jp.add(jsp);
            table.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent evt) {
                    if(evt.getButton() == 3) {
                        System.out.println("Right Click........");
                        // Mouse left click should be forced here to select the row.
                    if(evt.getButton() == 1) {
                        System.out.println("Mouse LEFT CLICK FORCED.....");
            getContentPane().add(jp);
            pack();
            setVisible(true);
        public static void main(String args[])
            new TableDemo();
    }

    There may be a better way, but you could just use java.awt.Robot to perform the left click. I've changed your code around a bit: it shouldn't extend JFrame as it is in no way a special type of JFrame. And a GUI should always be launched on the EDT.**import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ForceLeftClick {
       private JTable table;
       private void makeUI() {
          String columnNames[] = {"Column 1", "Column 2", "Column 3"};
          String dataValues[][] = {
             {"12", "234", "67"},
             {"-123", "43", "853"},
             {"93", "89.2", "109"},
             {"279", "9033", "3092"}
          table = new JTable(dataValues, columnNames);
          JScrollPane scrollPane = new JScrollPane(table);
          scrollPane.setViewportView(table);
          table.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseClicked(final MouseEvent evt) {
                if (evt.getButton() == MouseEvent.BUTTON3) {
                   System.out.println("Right Click........");
                   // Mouse left click should be forced here to select the row.
                   //final Point point = evt.getLocationOnScreen();
                   SwingUtilities.invokeLater(new Runnable() {
                      @Override
                      public void run() {
                         try {
                            Robot robot = new Robot();
                            //robot.mouseMove(point.x, point.y);
                            robot.mousePress(InputEvent.BUTTON1_MASK);
                            robot.mouseRelease(InputEvent.BUTTON1_MASK);
                         } catch (AWTException ex) {
                            ex.printStackTrace();
                if (evt.getButton() == MouseEvent.BUTTON1) {
                   System.out.println("Mouse LEFT CLICK FORCED.....");
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(scrollPane);
          frame.pack();
          frame.setVisible(true);
       public static void main(String args[]) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new ForceLeftClick().makeUI();
    }If there are issues of Robot clicking in the wrong location because the user moves the mouse before the robot does its stuff (not likely, but..), uncomment the two commented lines.
    db
    **edit And always use constant fields by name, not magic numbers. MouseEvent.BUTTON1, not 1. That keeps your code implementation independent.
    Edited by: Darryl.Burke

  • 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.

  • Need a shortcut to "Allow pages to choose their own colors, instead of my selections above option preference" I know where it is and how to use it but I have to go through 7 mouse clicks to change it, then a few minutes later change it back. I also k

    Need a shortcut to "Allow pages to choose their own colors, instead of my selections above option preference" I know where it is and how to use it but I have to go through 7 mouse clicks to change it, then a few minutes later change it back. I also know the sequnce is alt t, alt o, alt c, alt a, then ok, ok. Got to be a way to make a one key short cut for this. I use a black background to reduce eye strain, but about 10% of the webpage I go to can't be send with black so I have to go into tools and hit 6 or 7 things to chnage it then after through with webpage have to do it all over at Not allow webpages to have own color. Very very cumbersome.
    == This happened ==
    A few times a week
    == made that way

    https://addons.mozilla.org/en-US/firefox/addon/toggledocumentcolors-198916/
    The above addon will solve your problem.
    Shortcut to toggle user color/page color :- Ctr+Shift+C

  • Multiple JButtons inside JTable cell - Dispatch mouse clicks

    Hi.
    I know this subject has already some discussions on the forum, but I can't seem to find anything that solves my problem.
    In my application, every JTable cell is a JPanel, that using a GridLayout, places vertically several JPanel's witch using an Overlay layout contains a JLabel and a JButton.
    As you can see, its a fairly complex cell...
    Unfortunately, because I use several JButtons in several locations inside a JTable cell, sometimes I can't get the mouse clicks to make through.
    This is my Table custom renderer:
    public class TimeTableRenderer implements TableCellRenderer {
         Border unselectedBorder = null;
         Border selectedBorder = null;
         public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                   boolean hasFocus, int row, int column) {
              if (value instanceof BlocoGrid) {
                   if (isSelected) {
                        if (selectedBorder == null)
                             selectedBorder = BorderFactory.createMatteBorder(2,2,2,2, table.getSelectionBackground());
                        ((BlocoGrid) value).setBorder(selectedBorder);
                   } else {
                        if (unselectedBorder == null)
                             unselectedBorder = BorderFactory.createMatteBorder(2,2,2,2, table.getBackground());
                        ((BlocoGrid) value).setBorder(unselectedBorder);
              return (Component) value;
    }and this is my custom editor (so clicks can get passed on):
    public class TimeTableEditor extends AbstractCellEditor implements TableCellEditor {
         private TimeTableRenderer render = null;
         public TimeTableEditor() {
              render = new TimeTableRenderer();
        public Component getTableCellEditorComponent(JTable table, Object value,
                boolean isSelected, int row, int column) {
             if (value instanceof BlocoGrid) {
                  if (((BlocoGrid) value).barras.size() > 0) {
                       return render.getTableCellRendererComponent(table, value, isSelected, true, row, column);
             return null;
        public Object getCellEditorValue() {
            return null;
    }As you can see, both the renderer and editor return the same component that cames from the JTable model (all table values (components) only get instantiated once, so the same component is passed on to the renderer and editor).
    Is this the most correct way to get clicks to the cell component?
    Please check the screenshot below to see how the JButtons get placed inside the cell:
    http://img141.imageshack.us/my.php?image=calendarxo9.jpg
    If you need more info, please say so.
    Thanks.

    My mistake... It worked fine. The cell span code was malfunctioning. Thanks anyway.

Maybe you are looking for

  • Lost some of my purchases how can I get them back?

    Hi I have lost some of my purchasesd when I had to format my hard drives and lost most of my music. I hadn't backed up my itunes library, which I will do as a matter of course from now one, but is there a way I can download some of the itunes I have

  • Cheque bounced

    Hi, In SAP Business one , how cheque bounced can be handled. eg. I have received a payment from customer. And deposited in the bank. I have used Incomming payments window  for receving the payment  from customer against the invoice. Now i have used t

  • Load Balancing with ACE using HTTP Header information

    Hello, I am trying to setup a class-map using http loadbalance match-all. What I want to do is check for the HTTP Host and if it doesnot match the http referer than go to server farm A. if it does match then go to server farm B. My problem is the hos

  • Error occurescan;t attatch library webutil

    hello and hi me install new form 10g with form 9i when i attach webutil.pll with a form and write a code at bush button for open dialog box DECLARE mDialog VARCHAR2(100); BEGIN WEBUTIL_BROWSER.browsermessage (WEBUTIL_FILE_TRANSFER.GET_WORK_AREA()); m

  • Mysterious formatting columns table

    Hi all, i don't post a problem, but a curiosity. I'm managing a Oracle BI environment developed by others, so many aspects are unknown for me. I've observed that if i make an Answers request dragging and dropping any columns from my subject area, any