JTable overrides the accelerator on JMenuItem

I have a JFrame which has a JMenu. Some of the menu items have accelerators associated with them. And the JFrame has a JTable. The accelerators are working only when the focus is not in the JTable. But they are not working when the focus is in JTable. For example, when I selected a row in the table and press the accelerator key, it is not working. Can somebody provide me the solution for it?

Here is the code:
public class SwingEventPropagationTest {
     private static final int shortcutKeyAsciiValue = 65; //A
     public static void main(String[] args) {
          final JFrame frame = new JFrame();
          JMenuBar menuBar = new JMenuBar();
          JMenu menu = new JMenu("Edit");
          JMenuItem menuItem = new JMenuItem("Test");
          KeyStroke ctrlAKeyStroke = KeyStroke.getKeyStroke(shortcutKeyAsciiValue, InputEvent.CTRL_MASK);
          menuItem.setAccelerator(ctrlAKeyStroke);
          menuItem.addActionListener(new SelectAllAction());
          menu.add(menuItem);
          menuBar.add(menu);
          frame.setJMenuBar(menuBar);
          final JTable table = new JTable(new NumericTableModel());
          //Remove Keybindings from table
          table.getInputMap().put(ctrlAKeyStroke, "doNothing");
          table.getActionMap().put("doNothing", new DoNothingAction());
          JScrollPane scrollpane = new JScrollPane(table);
          JPanel panel = new JPanel();
          panel.add(new JButton("test"));
          panel.add(scrollpane);
          frame.getContentPane().add(panel);
          frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          frame.setSize(500,500);
          frame.setVisible(true);
     private static class NumericTableModel extends AbstractTableModel{
          public int getColumnCount() { return 2; }
          public int getRowCount() { return 10;}
          public Object getValueAt(int row, int col) {
               int value = (row*2) + (col+1);
               return value;
     private static class SelectAllAction extends AbstractAction{
          public void actionPerformed(ActionEvent e) {
               //This should be shown when Shortcut Key is pressed
               JOptionPane.showMessageDialog(null, "Worked");
     private static class DoNothingAction extends AbstractAction{
          public void actionPerformed(ActionEvent e) {
               //do nothing
}

Similar Messages

  • Override the ToolTipText of the JTable with JButton ToolTipTex(pls see msg)

    Hi All,
    Could you please me to solve this problem?
    I have two Icons display on 2 JButtons (2 different ToolTipText for buttons). The Buttons are display on a JPanel. The Panel is display on one of the cell inside JTable. Is it possible that when I move the mouse over each Icon it will displays the ToolTipText of each of the JButton (I am try to replace the ToolTipText of the JTable with the ToolTipText of the JButton when mouse over and when I move the mouse to the next JButton I get a different ToolTipText). The reason I am using the JButton is that in the future I will add actionListener() to do something when the user click on it.
    I have try working with glassPane, addMouseMotionListener, MouseEvent.getPoint(), SwingUtilities.convertPoint, SwingUtilities.getDeepestComponentAt.
    Thank you in advance.
    Note: I am getting the Icons from Object [].

    Hello, the following is one ugly piece of code but I guess that's pretty much what you were after. Just test the tooltip and you'll see that it depends both on the cell and on which of the two buttons is hovered.import javax.swing.*;
    import javax.swing.table.TableCellRenderer;
    import java.awt.*;
    import java.awt.event.MouseEvent;
    public class TestTooltipTable {
         private static class CustomTableCellRenderer implements TableCellRenderer {
              private JButton theLeftButton;
              private JButton theRightButton;
              private JPanel thePanel;
              public CustomTableCellRenderer() {
                   theLeftButton = new JButton("left action");
                   theRightButton = new JButton("right action");
                   thePanel = new JPanel(new GridLayout(1, 2)) {
                        public String getToolTipText(MouseEvent e) {
                             Point p = e.getPoint();
                             Rectangle leftRect = theLeftButton.getBounds();
                             Rectangle rightRect = theRightButton.getBounds();
                             if (leftRect.contains(p)) {
                                  return theLeftButton.getToolTipText();
                             } else if (rightRect.contains(p)) {
                                  return theRightButton.getToolTipText();
                             return " ";
                   thePanel.add(theLeftButton);
                   thePanel.add(theRightButton);
              public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                                                                        boolean hasFocus, int row, int column) {
                   String text = (String)value;
                   theLeftButton.setToolTipText("left action " + text);
                   theRightButton.setToolTipText("right action " + text);
                   return thePanel;
         public static void main(String[] args) {
              final JFrame frame = new JFrame(TestTooltipTable.class.getName());
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              Object[][] data = {{"1", "A"}, {"2", "B"}, {"3", "C"}};
              String[] columnNames = {"Number", "Letter"};
              JTable table = new JTable(data, columnNames) {
                   public String getToolTipText(MouseEvent event) {
                        return super.getToolTipText(event);
              table.setDefaultRenderer(Object.class, new CustomTableCellRenderer());
              ToolTipManager.sharedInstance().registerComponent(table);
              frame.getContentPane().add(new JScrollPane(table));
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        frame.pack();
                        frame.show();
    }

  • [svn:fx-trunk] 13366: Ensuring that AFEFontManager, if it is available, overrides the lookup for embedded fonts for all supported font types, including TTF, when embedding legacy DefineFont3 fonts.

    Revision: 13366
    Revision: 13366
    Author:   [email protected]
    Date:     2010-01-07 22:15:50 -0800 (Thu, 07 Jan 2010)
    Log Message:
    Ensuring that AFEFontManager, if it is available, overrides the lookup for embedded fonts for all supported font types, including TTF, when embedding legacy DefineFont3 fonts. BatikFontManager will remain a backup in the event that AFEFontManager is not found though BatikFontManager;s support is limited to TTF for legacy DefineFont3 fonts.
    QE notes: Remember that bitmap comparisons could change slightly
    Doc notes: N/A
    Bugs: N/A
    Reviewer: For Gaurav
    Tests run: checkintests, QE had run local tests
    Is noteworthy for integration: Yes
    Modified Paths:
        flex/sdk/trunk/frameworks/flex-config.xml

    I got again a total system freeze today when I wanted to launch firefox using only the openbox menu, without wbar running.
    So I decided to try now the 'nouveau.noaccel=1' kernel command line parameter, and to use again wbar for my frequently used applis.
    In the Xorg log, the differences are:
    without 'nouveau.noaccel=1'
    [ 30.761] (II) UnloadModule: "nv"
    [ 30.761] (II) Unloading nv
    [ 30.761] (--) Depth 24 pixmap format is 32 bpp
    [ 30.762] (II) NOUVEAU(0): Opened GPU channel 0
    [ 30.765] (II) NOUVEAU(0): [DRI2] Setup complete
    [ 30.765] (II) NOUVEAU(0): [DRI2] DRI driver: nouveau
    [ 30.765] (II) NOUVEAU(0): [DRI2] VDPAU driver: nouveau
    [ 30.776] (II) EXA(0): Driver allocated offscreen pixmaps
    [ 30.777] (II) EXA(0): Driver registered support for the following operations:
    [ 30.777] (II) Solid
    [ 30.777] (II) Copy
    [ 30.777] (II) Composite (RENDER acceleration)
    [ 30.777] (II) UploadToScreen
    [ 30.777] (II) DownloadFromScreen
    [ 30.777] (==) NOUVEAU(0): Backing store disabled
    [ 30.777] (==) NOUVEAU(0): Silken mouse enabled
    with 'nouveau.noaccel=1'
    [ 1191.621] (II) UnloadModule: "nv"
    [ 1191.621] (II) Unloading nv
    [ 1191.621] (--) Depth 24 pixmap format is 32 bpp
    [ 1191.621] (EE) NOUVEAU(0): Error creating GPU channel: -19
    [ 1191.621] (EE) NOUVEAU(0): Error initialising acceleration. Falling back to NoAccel
    [ 1191.621] (==) NOUVEAU(0): Backing store disabled
    [ 1191.621] (==) NOUVEAU(0): Silken mouse enabled
    [ 1191.621] (==) NOUVEAU(0): DPMS enabled
    So now 3D acceleration is disabled.
    I will see now if the system is stable enough for my daily usage and gives satisfactory performances.
    I am almost sure that the mesa nouveau dri driver is the cause of the freezes.
    Last edited by berbae (2013-03-27 10:07:42)

  • JTable - Swapping the Rows and Columns

    This issue was raised in the Java Programming forum. Received initially as a weird requirement, it now seems that it is more common than you might think. Under it's original title it was "JTable - Limitation or Not?"
    I introduced the topic here so that the thread perspective can include more experienced Swing developers.
    The JTable in it's default layout is intended to hold database tables with records in rows. But what if you want records in columns?
    Some have said why? Just accept the row layout. Others have said use a customised form. Both reasonable views. Despite this, others report that the inherrited power of the JTable is worth leveraging and they have been doing it for years. Albeit with messy code in certain cases.
    This is a clear candidate for a popular derived component. If the existing JTable were renamed as a JTableRecordPerRow I am describing a JTableRecordPerColumn. The corresponding Table Model must naturally have a getRowClass method and no getColumnClass method.
    Java is good at seperating data from display issues so essentially this is only a display issue. The data representation is unaffected.
    While this may be so, the TableModel for a JTable makes the link from the display to the data so it must have knowledge about cell type to trigger the correct cell editor for example.
    I think it is fair to say that the standard JTable has not be designed with alternative row/column or column/row displays in mind. Hence a single getColumnClass method. However implementing a Table model which exchanges columns for rows is a good start. This leaves a few loose ends where editting is concerned.
    While this may not be an ideal topic for anyone just learning Swing I have been encouraged to consider the general case within the limitations of the cell types normally supported by the default Table model.
    I would have a guess that this is an established component in many private Java libraries already.
    Views and experience on this topic extremely welcome.

    It appears to me that while interchanging the rows and columns of a JTable is not trivial it is still worthwhile as a workhorse component.
    Perhaps the original design could have allowed for an aternative layout manager of somekind but this could easily have made description of records/rows and fields/columns confusing.
    I will probably get this summary wrong but I aill attempt to collate the neatest approach as I see it. Criticisms or shorter steps welcome. My thanks to the original contributors traceable from this thread.
    In the descriptions below a distinction is made between the normal internal data model representation of a row, called "mrow", and the displayed form "row".
    Only the TableModel need be changed.
    1 Use row 0 to show the headers by a)disabling the normal TableHeader renderer b)setting the cell renderer for column 0 to the default renderer used by the TableHeader and c)using the getValueAt method to return mcol header values for the row entries.
    2 For other row, col values to getValueAt return the value at mcol, mrow where mcol==row-1 & mrow==col.
    3 Create a new getCellClass(col,row) method to return the class where mrow==0 and mcol==row-1. Note that I am only trying to immitate the common use of of a database record per mrow here.
    4 Override a)getCellRenderer and b)getCellEditor to use getCellClass
    Four steps with seven parts seems worth it to me.
    The power of Swing!
    Many thanks to all.

  • How to override the create method invoked by a create form?

    Hello everyone, I'm using ADF Faces and have the next question:
    How can I override the create method which is invoked by a create form to preset an attribute in the new row (the preset value is not fixed, I have to send it to the method as a parameter as it is obtained using an EL expression)?
    In the ADF guide I read how to override a declarative method (Section 17.5.1 How to override a declarative method), but this explains how to do it with a method that is called by a button. I don't know how to do the same with a method which is called automatically when the page is loaded.
    I also tried overriding the view object's createRow() method to receive a parameter with the preset values but it didn't work, I believe that was because the declarative create method is not the same as the view object's createRow. This caused the form to display another row from the viewobject and not the newly created one (I also set the new row into STATUS_INITIALIZED after setting the attribute).
    Well, I hope my problem is clear enough for somebody to help me.
    Thank you!

    Hello,
    I'm not sure you can do it with standard generated Create Form.
    In your view object you'll need to create your own create method with parameters, publish it to client interface and invoke instead of standard generated create action in page definition.
    Rado

  • I have photoshop CC. I cannot open two files such as Tiffs and view them side by side. When I open the second file it overrides the first. Do I need to do something with preferences?

    I have photoshop CC. I cannot open two files such as Tiffs and view them side by side. When I open the second file it overrides the first. Do I need to do something with preferences?

    What happens when you try to use the clone stamp tool?
    It should work with the images side by side.
    You can setup photoshop cc to be like photoshop cs2 was on your other mac, by going to Photoshop>Preferences>Interface and unchecking
    Open Documents as Tabs and Enable Floating Document Window Docking
    And also going to Window and unchecking Application Frame

  • HT204074 Is there anyway to override the 90 day timer on a device?

    Does anyone know if you can override the 90 day timer on a device? If an another ID is already associated with that device will it still work?

    You can't override the 90 days, you will need to wait until it's completed. I think that you can still sync content to the iPad from other accounts via your computer's iTunes (though iTunes match, automatic downloads and re-downloading can also tie a computer to an account)

  • Is it possible to override the built-in PDF format handler with a custom IFilter for PDF?

    Hi,
    SharePoint 2013 comes with a built-in "format handler" for PDF now, so it can index PDF files out of the box. This is great for most users, as it now no longer is necessary to install a third-party IFilter for crawling PDF documents.
    My question is, is it possible to override the built-in format handler for PDF with a custom IFilter for PDF? I played with the Set-SPEnterpriseSearchFileFormatState and Remove-SPEnterpriseSearchFileFormat cmdlets. While it is possible to deactivate
    the built-in format handler, I was not able to remove it and to create a new one that activates a custom IFilter for PDF files.
    Background of the question: While the new built-in format handler for PDF will probably be sufficient for many SharePoint users, some need additional capabilities regarding indexing if PDF documents, e.g. extraction of custom metadata from PDF's document
    information dictionary and embedded XMP metadata. PDFlib GmbH, the company I work form, sells an IFilter for PDF, and of course we would like to continue to offer this for SharePoint 2013.
    Thanks
    Stephan

    You should be able to replace it with any ifilter you want, this is the procedure for installing it:
    Install PDF iFilter 9.0 (64 bit) from
    http://www.adobe.com/support/downloads/detail.jsp?ftpID=4025 (http://www.adobe.com/support/downloads/detail.jsp?ftpID=4025)
    Download PDF icon picture from Adobe web site
    http://www.adobe.com/misc/linking.html (http://www.adobe.com/misc/linking.html)  and copy to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\IMAGES\
    Add the following entry in docIcon.xml file, which can be found at: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\XML
    <Mapping Key="pdf" Value="pdficon_small.png" />
    Add pdf file type on the File Type page under Search Service Application
    Open regedit
    Navigate to the following location:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\15.0\Search\Setup\ContentIndexCommon\Filters\Extension
    Right-click > Click New > Key to create a new key for .pdf
    Add the following GUID in the default value
    {E8978DA6-047F-4E3D-9C78-CDBE46041603}
    •Restart the SharePoint Server Search 15
    •Reboot the SharePoint servers in Farm
    •Create a Test site (with any out-of-box site template) and create a document library upload any sample PDF document(s).
    •Perform FULL Crawl to get search result.
    Once the crawl is completed we will get search results.
    Kind regards,
    Margriet Bruggeman
    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • How do I make my desktop MAC address book override the older addresses in my iPhone?

    I have the iPhone 3g and a MAC desktop with snow leopard OS.  I have updated iTunes.  When I try to synchronize my address book between iPhone and MAC desktop, the new contact information from the desktop is not put into the iPhone.  Is there an online tutorial that will show me how to do this?  Another problem, when I try to edit contact information, the Edit menu won't let me delete whole contacts.  Consequently, I have multiple phone numbers for a contact, some of which are old, some new...and I can't remember which, because I thought I had erased the old info.  I want to be able to set the desktop to override the iPhone data, and vice versa, when I want to.  By habit, I don't enter new data directly into my iPhone contact list; I do it from the desk top. 
         I would like to find online tutorial videos that show me how to use the various features of my iPhone.  The online text tutorials aren't as helpful for me, when something goes wrong.

    To make your computer overwrite your iPhone contacts, connect the phone to iTunes, select the Info pane and scroll to the Advanced section at the bottom and put a check by Contacts.  Then sync.

  • Help needed in overriding the finalize() method!

    Hi
    I need some help in overwriting the finalize() method.
    I have a program, but at certain points, i would like to "kill" a particular object.
    I figured that the only way to do that is to make that object's class override the finalize method, and call it when i need to kill the object.
    Once that is done, i would call the garbage collector gc() to hopefully dispose of it.
    Please assist me?
    Thanks
    Regards

    To, as you put it, kill an object, just null it. This
    will be an indication for the garbage collector to
    collect the object. In the finalizer, you marely null
    all fields in the class. Like this:
    public class DummyClass
    String string = "This is a string";
    Object object = new Boolean(true);
    public void finalize() throws Throwable
    super.finalize();
    string = null;
    object = null;
    public static void main(String[] args)
    //Create a new object, i.e allocate an
    te an instance.
    DummyClass cls = new DummyClass();
    //Null the reference
    cls = null;
    This is a pointless exercise. If an object is being finalized, then all the references it contains are about to cease being relevant anyway, so there's no purpose to be served in setting them to null.
    All that clearing a reference to an object does is to clear the reference. Whether the object is subsequently finalized depends on whether the object has become unreachable.
    Directly calling finalize is permitted, but doesn't usually serve any purpose. In particular, it does not cause the object to be released. Further, calling the finalize method does not consitute finalization of the object. Finalization occurs when the method is called as a consequence of a garbage collector action.
    If a variable contains a reference to an object (say a table), and you want a new table instead, then create a new table object, and assign its reference to the variable. Assuming that the variable was the only place that the old table's reference was stored, the old table will, sooner or later, get finalized and collected.
    Sylvia.

  • I changed my Apple ID and password, but when I attempt to update Apps I am prompted to enter my Password for my OLD Apple ID, and I am unable to override the Old Apple ID. How to proceed ?

    I changed my Apple ID and password, but when I attempt to update Apps I am prompted to enter my Password for my OLD Apple ID, and I am unable to override the Old Apple ID. How to proceed ?

    Delete everything bought with the old Apple ID and buy it again.
    Content and Apple IDs -
    Content is forever tied to the Apple ID that bought it. Apple does not transfer content from one Apple ID to another. Apple does not merge Apple IDs. You will never be able to access your content bought with one Apple ID with a new Apple ID.

  • I'd like to sync my iTouch and iPad with my PC, and have the content (both iTunes and uploaded music) on the devices override the content on the PC, but cannot seem to find a option to do that. Can anyone help me?

    I had to have my PC wiped clean and the OS re-loaded. I thought I backed up everything  on my iTouch and iPad correctly, but when I try to sync, I'm getting a message that if I continue with the sync, I will lose everything on my device. I'd like to sync and have the content (both iTunes purchased music/apps and uploaded music) override the content on my PC, but am unable to find a way to do that. I have the first gen iTouch that does not support iCloud. Can anyone help?

    My question is, can I listen to all the audio that come out from the ipad (movies online, games, Goear…) or only to the music from iTunes library?
    On the iPad you can stream videos, photos, or music from the Video, Photos, Music, and YouTube apps to an Apple TV OR just stream music to an AirPort Express Base Station.

  • Override the element mapped in the IMPL.xsl file to NULL in CUSTOM.xsl

    Hi Guys,
    we are trying to override the element mapped in the IMPL.xsl file to NULL in CUSTOM.xsl file using call template. But we are getting the target mapped twice instead of overriding. kindly help.
    IMPL.xsl_
    <db:LONG_DESCRIPTION xml:id="id_102">
    <xsl:value-of select="corecomEBO:RevisedItem/corecomEBO:Description" xml:id="id_103"/>
    </db:LONG_DESCRIPTION>
    <xsl:call-template name="LONG_DESCRIPTION_Custom"/>
    Custom.xsl_
    <xsl:template name="LONG_DESCRIPTION_Custom">
    <db:LONG_DESCRIPTION xmlns:db="http://xmlns.oracle.com/pcbpel/adapter/db/APPS/INV_EBI_CHANGE_ORDER_PUB/PROCESS_CHANGE_ORDER_LIST/" xml:id="id_102" >
    <xsl:value-of select="''"/>
    </db:LONG_DESCRIPTION>
    </xsl:template>
    OUTPUT_
    <db:LONG_DESCRIPTION xml:id="id_102">XXX</db:LONG_DESCRIPTION>
    <db:LONG_DESCRIPTION xmlns:db="http://xmlns.oracle.com/pcbpel/adapter/db/APPS/INV_EBI_CHANGE_ORDER_PUB/PROCESS_CHANGE_ORDER_LIST/" xml:id="id_102" />
    Needed OUTPUT_
    <db:LONG_DESCRIPTION xmlns:db="http://xmlns.oracle.com/pcbpel/adapter/db/APPS/INV_EBI_CHANGE_ORDER_PUB/PROCESS_CHANGE_ORDER_LIST/" xml:id="id_102" />
    Thanks in advance.

    Just change what you're doing in that servlet to write that extra line.
    Since you didn't say anything about how you're writing your XML file, it's pretty hard to suggest what exactly you should change.

  • IDOC Overrides the data in SAP

    Hi Experts,
    I am working on MDM 7.1 SP5 Vendor Master Implementation. We are maintaining all the SAP data in MDM and there is no manual intervenation at SAP ECC
    So we have used standard repository , CREMDM04 as XSD and the standard process code for IDOC
    Later Business has decided to maintain only one field Search Term 2 directly in SAP ECC and not part of MDM
    So i have unmapped that field in the Syndication map, and also in the PI mapping .
    When we syndicate the data from MDM to SAP, the IDOC overrides the search term 2 directly maintained in SAP ECC
    When i checked in the IDOC posted to ECC, this field SORT2 is not part of it.
    As a workaround, though SORT2 is part of only ADRMAS, still i have passed / though it is not mapped. But no luck
    Could you kindly help me to resolve this
    Regards,
    Antony

    Hi Rajesh,
    I have mapped the SORT2 in MDM & as well as PI with the value /
    In IDOC the sort2 value is going as / and over rides the value in SAP
    I believe the / concept will work only for CREMAS so that it will not over ride the ADRMAS data which is posted to SAP
    Please advice is there any work around as this issue hampers our go live
    Regards,
    Antony

  • How to generate and view the link of the accelerator

    Hi All,
    I want to generate a link for the accelerator added in Roadmap, I know that I can do it through the button Generate URL of the document attributes,but the problem is, when i click on the button, it says URL generated. Where can I view the link which is generated for a particular document.
    If I see in Solar01 or Solar02 documents, there is seperate tab by name LINK, but there also I am not able to view the link generated.
    Pls help me with your inputs ASAP.
    Thanks & Regards,
    Bharathi

    Hi prakar,
    For some of the documents without asking for user name and password it is displaying ( This is depending on the Local and the client system).
    I mean for the internal SolMan system, its displaying the document, when I do the samething for the client system, it says page not found.
    Pls let me know the settings to be done for me to view the document.
    I will have to use my SolMan username and password to open the document, Correct me if I am wrong.
    Pls let me know the roles to be provided to give access to the user.
    Regards,
    Bharathi.

Maybe you are looking for

  • Interlacing issue with AME/Premiere CS5?

    Hi, I am having some issues with a file that I am trying to conform using AME CS5 from XDCAM-HD mxf wrapped to wmv output that I need to be able to playout of a black magic card to SDI. The source file is 25fps PAL If I import the mxf directly into A

  • How to Download "HP Solution Center" for Deskjet 6988 on Windows 8.1

    I have a Deskjet 6988 printer and a Scanjet G3110 on Windows 8.1 and can only get the basic drivers to download for them.  I can scan and print, but  I want the HP Solution Center software downloaded so I can control making copies.  How do I do that?

  • Viewing Flash Across different browsers?

    Is it capable of letting me view flash work across the browsers?

  • IChat AV on Leopard now working

    thanks to Ralph's message and bhagemann's reply, iChat AV/Leopard is now working for me. I'm going away for a while and I have been trying to get iChat AV working reliably so that I can video chat with my wife while I'm away, but every attempt to con

  • Connection to Portal over Citrix

    We have successfully set up the connection to our company portal via citrix login. Everything runs smoothly except one thing. During the log off from the portal a small blank popup window remains visible. Any ideas? Best regards, Thomas