Stopping right click selecting tab in JTabbedPane

Hello all,
This may be a really simple thing + I'm probably being thick, but is there a way to prevent a right click changing the selected tab on a JTabbedPane.
I tried consuming the MouseEvent, but that didn't seem to work. Couldn't find an answer anywhere else in the forums & couldn't see anything in the JavaDoc that looked as if it would help.
Answers on a postcard please......
RT

You might be able to extend JTabbedPane and override setSelectedIndex().
I had to do this to work around a focus issue I had.
  This class extends JTabbedPane to correct a problem where it doesn't
  request focus when clicked on.
import java.awt.*;
import javax.swing.*;
public class MyJTabbedPane extends JTabbedPane {
  public void setSelectedIndex(int index) {
    Component comp = KeyboardFocusManager.
        getCurrentKeyboardFocusManager().getFocusOwner();
    //  if  no tabs are selected
    // -OR- the current focus owner is me
    // -OR- I request focus from another component and get it
    // then proceed with the tab switch
    boolean noTabSelected = getSelectedIndex()==-1;
    boolean hasFocus = requestFocus(false);
    boolean compIsMe = comp==this;
    if(noTabSelected || hasFocus || compIsMe) {
      super.setSelectedIndex(index);
}

Similar Messages

  • MY FIREFOX NEW TAB NOT WORKING NIETHER WITH + NOR WITH RIGHT CLICKING ON TAB OR DOUBLE CLICK ON TAB

    MY FIREFOX NEW TAB NOT WORKING NIETHER WITH + NOR WITH RIGHT CLICKING ON TAB OR DOUBLE CLICKING ON TAB

    '''Try Firefox Safe Mode''' to see if the problem goes away. [[Troubleshoot Firefox issues using Safe Mode|Firefox Safe Mode]] is a troubleshooting mode that temporarily turns off hardware acceleration, resets some settings, and disables add-ons (extensions and themes).
    If Firefox is open, you can restart in Firefox Safe Mode from the Help menu:
    *In Firefox 29.0 and above, click the menu button [[Image:New Fx Menu]], click Help [[Image:Help-29]] and select ''Restart with Add-ons Disabled''.
    *In previous Firefox versions, click on the Firefox button at the top left of the Firefox window and click on ''Help'' (or click on ''Help'' in the Menu bar, if you don't have a Firefox button) then click on ''Restart with Add-ons Disabled''.
    If Firefox is not running, you can start Firefox in Safe Mode as follows:
    * On Windows: Hold the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
    * On Mac: Hold the '''option''' key while starting Firefox.
    * On Linux: Quit Firefox, go to your Terminal and run ''firefox -safe-mode'' <br>(you may need to specify the Firefox installation path e.g. /usr/lib/firefox)
    When the Firefox Safe Mode window appears, select "Start in Safe Mode".<br>
    [[Image:Safe Mode Fx 15 - Win]]
    '''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, theme, or hardware acceleration. Please follow the steps in the [[Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems]] article to find the cause.
    ''To exit Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
    When you figure out what's causing your issues, please let us know. It might help others with the same problem.

  • Changing Colors of selected tab in JTabbedPane.

    Do someone has some code that can show how to
    change the color of the selected tab with JTabbedPane.
    I can change the other tabs colors with setBackground and setForeground, setBackgroundAt........ but it is the selected
    tab that will not change from the default grey color.
    thanks

    try this code, it works.
    public class TabBackgroundChange extends JFrame {
    private JTabbedPane tabPane = null;
    public static final Color selTabColor = Color.red;
    Color nonSelectedTabColor = null;
    public TabBackgroundChange() {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch(Exception ex) {
    ex.printStackTrace();
    tabPane = new JTabbedPane();
    tabPane.add("One", new JPanel());
    tabPane.add("Two", new JPanel());
    tabPane.add("Three", new JPanel());
    this.getContentPane().add(tabPane);
    this.setSize(200, 200);
    this.setVisible(true);
    tabPane.addChangeListener(new TabChangeListener());
    tabPane.setSelectedIndex(1);
    tabPane.setSelectedIndex(0);
    public static void main(String[] args) {
    TabBackgroundChange tabBackgroundChange1 = new TabBackgroundChange();
    private class TabChangeListener implements ChangeListener {
    public void stateChanged(ChangeEvent ce) {
    int iSelTab = tabPane.getSelectedIndex();
    Color unSelectedBackground = tabPane.getBackgroundAt(iSelTab);
    for(int i=0; i<tabPane.getTabCount(); i++) {
    tabPane.setBackgroundAt(i, unSelectedBackground);
    tabPane.setBackgroundAt(iSelTab, Color.red);
    }

  • I have 5.0 What happened to right-click a tab and the Save as bookmark option?

    I have 5.0 What happened to right-click a tab and the Save as bookmark option?

    "Bookmark This Page" can be accessed via the right-click context menu of that browser page or via "(Firefox) > Bookmarks > Bookmark This Page".
    *https://support.mozilla.com/kb/how-do-i-use-bookmarks

  • Allow right-click selection in a JTree

    Hi everybody! How are today? Fine? I hope so.
    I've got a little question about JTrees: i want to put a right-click popup menu on my JTree, which may not be the same depending on which node of the tree is selected.
    My problem is that i must do a left click selection of the node before doing the right click in order that this one may be effective and correct (i.e the correct popup menu appears).
    So, i want to allow the right click selection in my JTree to select the node and to perform the action linked to the Popup menu.
    I will be very thankfull if someone could help me :)

    Sorry to post twice, but just thought i'd post the code to show you what I mean (forgive me not making this entirely generic):
    ///// Some "global" variables:
         private JPopupMenu               stPopupMenu;
         private TreePath               stPath;
         private String                    stPathComponent;
         private int                         stCount;
         private Object                    selectedNode;
    ///// Attaching the listeners:
    symbolTreeDisplay.addTreeSelectionListener(stHandler);
    symbolTreeDisplay.addMouseListener(stHandler);
    //// The event listener class:
         private class SymbolTreeHandler extends MouseAdapter implements
                   TreeSelectionListener
              public void mouseClicked(java.awt.event.MouseEvent event)
                   try
                        if (event.getModifiers() == event.BUTTON3_MASK)
                        {//right button click on mouse
                             stPopupMenu = new JPopupMenu();
                             // add your logic here, based on selectedNode to add items to the menu
                             stPopupMenu.show(symbolTreeDisplay, event.getX(), event
                                       .getY());
                   catch (Exception e)
              public void valueChanged(TreeSelectionEvent aTreeEvent)
                   try
                        stPath = aTreeEvent.getPath();
                        stCount = stPath.getPathCount();
                        selectedNode = stPath.getPathComponent(stCount - 1);
                   catch (Exception e)
         }

  • Right clicking a tab and opening new tab next to it

    I want to right click a tab and have one fo the options be: open tab immediately after
    I can do this in Chrome
    Is there a BASIC plugin for this
    I say basic: I want something that won't hog the browser taking up resources - I've had troubles with other tab plugins
    Thanks
    Omar

    You can't do that without an extension.
    You can try:
    *Tab Utilities Lite: https://addons.mozilla.org/firefox/addon/tab-utilities-lite/

  • Firefox Groups installed but Right-click on Tab shows no menu. I have one rogue AppTab I am trying to delete and cannot. Any answers?

    How do I get a menu upon right-clicking a tab in Groups (Panorama)? Thanks in advance.

    New Groups. No you are correct. Haven't added any recently, so hadn't noticed.
    Tell Apple
    http://www.apple.com/feedback/macosx.html
    Good Luck
    Pete

  • Right Click - no Tab option

    I just updated Safari and now I have lost the option of right-click New Tab. All I have is Open in New Window.
    Does anyone know how I get back the option for Open in New Tab?
    Muz

    Ok...
    Go to the Safari Menu Bar, click Safari/Preferences. Make note of all the preferences under each tab. Quit Safari. Now go to ~/Library/Preferences and move this file com.apple.safari.plist to the Desktop. Relaunch Safari. If Safari tabs are ok, then move that .plist file to the Trash.
    Please keep your forum profile available in all your posts. Makes it much easier then scrolling back and forth.
    Sometimes just restarting your Mac can help too.

  • Stop Right click and dragging

    How do I stop right click save and also dragging of images from my site - I am not bothered about screen shots because at the enbd of the day - its just a screen shot.
    Is there any way to do this on Muse or is there some code that I have to insert - I have seen a few disscusssions where they say you have to insert code - though nothing which really states what code and where to put it.
    Also can any one explain meta data to me please and if I should apply it to my images as an extra precaution?
    Thanks for the help
    Mark

    The associations menue in Bridge affects right clicking in Bridge only and has nothing to do with the file associations in Windows 7.
    I am not trying to right click and edit a jpg file in Bridge! I am using the Windows explorer or desktop.
    I need to find out how to change the file association for right click and edit with a jpg in Windows 7.
    Thanks

  • Stop right click Event on JTabbedPane

    Hi,
    Does anyone know how to stop tabbed pane changing by right click of the mouse? I still want left click to change.
    Thanks a lot.
    Qian

    The proper way to do this is to write a custom UI as this behaviour is controlled by the UI.
    As a quick hack you can replace the deault MouseListener with a custom MouseListener. The listener code below was taken from the BasicTabbedPaneUI and slightly modified:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TabbedPaneNoRightClick extends JFrame
        public TabbedPaneNoRightClick()
            JTabbedPane tabbedPane = new JTabbedPane();
            getContentPane().add(tabbedPane);
            newTab(tabbedPane, "one");
            newTab(tabbedPane, "two");
            newTab(tabbedPane, "three");
            newTab(tabbedPane, "four");
            MouseListener[] ml = (MouseListener[])tabbedPane.getListeners(MouseListener.class);
            for (int i = 0; i < ml.length; i++)
                tabbedPane.removeMouseListener( ml[i] );
            tabbedPane.addMouseListener(new MouseAdapter()
                public void mousePressed(MouseEvent e)
                    JTabbedPane tabbedPane = (JTabbedPane)e.getSource();
                    if (!tabbedPane.isEnabled()
                    ||  SwingUtilities.isRightMouseButton( e ))  // added
                        return;
                    // int tabIndex = getTabAtLocation(e.getX(), e.getY()); // changed
                    int tabIndex = tabbedPane.getUI().tabForCoordinate(tabbedPane, e.getX(), e.getY());
                    if (tabIndex >= 0 && tabbedPane.isEnabledAt(tabIndex))
                        if (tabIndex == tabbedPane.getSelectedIndex())
                            if (tabbedPane.isRequestFocusEnabled())
                                tabbedPane.requestFocus();
                                //tabbedPane.repaint(getTabBounds(tabPane, tabIndex)); // changed
                                tabbedPane.repaint(tabbedPane.getUI().getTabBounds(tabbedPane, tabIndex));
                        } else
                            tabbedPane.setSelectedIndex(tabIndex);
        private void newTab(JTabbedPane tabbedPane, String text)
            JLabel label = new JLabel(text);
            tabbedPane.addTab( text, label );
        public static void main(String args[])
            TabbedPaneNoRightClick frame = new TabbedPaneNoRightClick();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.setSize(200, 100);
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
    }

  • Stop Right Clicks from automatically Opening link in new tab?

    So Normally I would right click a link, scroll down to "Open link in new tab" or "Open link in new Window" ect ect. But now, before I can choose which option I want (tab or window) it automatically opens the link up in a new tab. it does it for every single link... Even if I just want to copy a link (left click and highlight) it will automatically open the link up anyway.. How do I stop it from doing that?!?! It is extremely frustrating.. I don't want everything I right click to be opened in a new tab
    Thank you ever so much for any help!

    Tried in Safe mode already and the problem still occurs.. I recently re installed windows on my laptop, and the only ad ons I have is flash block, ad block and adobe flash player. I tried with all disabled, as well as disabling all the extensions.. still same issue..
    I'm sorry this might have been important issue but I am using a USB mouse. the touchpad/clicker on my laptop works normally.. I can right click with the touch pad and it gives me options instead of automatically opening it.. could it be an issue withe the USB mouse? Ive never had issuse with it before I re-installed windows. the usb ports are kept clean and the mouse has fresh batteries..

  • Firefox 6. When right clicking a tab no drop-down menu appears. Why do I not have the option to pin, unpin, etc.

    I'm using Firefox 6 with all current updates. This is on a desktop pc running Windows XP (Service Pack 3).
    At some previous time I was able to pin tabs - I pinned three. Lately I do not have a drop-down menu when right clicking on a pinned or unpinned tab. The feature is just not there.

    Try the Firefox SafeMode. <br />
    ''A troubleshooting mode, which disables most Add-ons.'' <br />
    ''(If you're not using it, switch to the Default Theme.)''
    # You can open the Firefox 4/5/6/7 SafeMode by holding the '''Shft''' key when you use the Firefox desktop or Start menu shortcut.
    # Or use the Help menu item, click on '''Restart with Add-ons Disabled...''' while Firefox is running. <br />
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before using the Firefox shortcut (without the Shft key) to open it again.''
    If it is good in the Firefox SafeMode, your problem is probably caused by an extension, and you need to figure out which one. <br />
    http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes

  • Right click select node in tree (for a standalone Air app)?

    For the sake of userfriendliness (in regard to a context menu) I wold like to "move" the selected node in a tree to the node that currently has the focus when right clicking it - like how the context menu access in windows file explorer works (focus and selected item are always the same  when right clicking).
    In worst case scenario I would like to disable a created context menu if the selected node and the node that currently has the focus are not the same).
    Now users can get confused when right clicking to access my context menu, in the tree structure, if the selected node and the node they are currently hovering over (and thus are in focus) are different.
    I was thinking of finding which node currently has the focus and then making that node the selected node - but I cant get it to work:-).
    Please, help a beginner.

    Hi,
    Duplicate thread of
    http://swforum.sun.com/jive/thread.jspa?threadID=64518
    MJ

  • Right click selection issue

    I am using HP Laptop with window 8.1.
    The right click button on the keyboard is not available so till the time I was using mouse for the right click.
    Now I install Hotkeys software & configure right Alt button of the keyboard as a right click button.
    It is working fine means whenever I clicked on the right Alt it is working as a right click, this is helpful in excel specially.
    But after this I am facing a new issue, this issue is when I using excel or word.
    When I move the cursor & select any cell with the mouse & then click on right alt it work properly.
    But after the selection from the mouse if I change the location by using arrow keys of the keyboard the location get changed but after changing the selection when I click on right Alt button the right click options open for the cell which was selected by
    the mouse.
    Hope it is clear.
    Example- If I select A5 location in excel by mouse & then goes right with keyboard right click on C5 location, the selection goes to the desired location, but if now I click on right Alt to open the options the cursor automatically opened the properties
    of A5 instead of C5.
    Here I clicked by mouse on A5 & moves to C5 by keyboard.
    Please help.
    This is  not an issue of scroll lock.

    I am using HP Laptop with window 8.1.
    The right click button on the keyboard is not available so till the time I was using mouse for the right click.
    Now I install Hotkeys software & configure right Alt button of the keyboard as a right click button.
    It is working fine means whenever I clicked on the right Alt it is working as a right click, this is helpful in excel specially.
    But after this I am facing a new issue, this issue is when I using excel or word.
    When I move the cursor & select any cell with the mouse & then click on right alt it work properly.
    But after the selection from the mouse if I change the location by using arrow keys of the keyboard the location get changed but after changing the selection when I click on right Alt button the right click options open for the cell which was selected by
    the mouse.
    Hope it is clear.
    Example- If I select A5 location in excel by mouse & then goes right with keyboard right click on C5 location, the selection goes to the desired location, but if now I click on right Alt to open the options the cursor automatically opened the properties
    of A5 instead of C5.
    Here I clicked by mouse on A5 & moves to C5 by keyboard.
    Please help.
    This is  not an issue of scroll lock.

  • Bug in right click selection in reports

    Build 22.71, on Linux and Windows.
    When I go to, for example, the sessions report, and right click on a row which I want to invoke a trace session command on, the whole column where I right clicked get selected, so it does not correctly indicate to the user which session will have trace enabled on.

    Add mouselistener:
    MouseListener ml = new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
             if (SwingUtilities.isRightMouseButton(e)) {
               doSomething();
          }//mousePressed
          public void mouseReleased(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
              doSometing();
          }//mouseReleased
        };//mouseListener
        myList.addMouseListener(ml);

Maybe you are looking for

  • Refresh every second

    Hi guys! I would like to refresh a label every second, and keep doing this. What can I use? Should be better to do the refresh in a different Thread? thank you!

  • Integrate DMS / SAP Content Server 6.40  with EP

    Hello , With reference to [DMS Installation |DMS Installation; integrate DMS / SAP Content Server 6.40 with EP to access EP PCD . Regards , Santosh

  • Can I install CC with CS4 on my computer?

    Hello, My name is Margo, I have photoshop CS4. It is running slow and crashes everytime I try to save edits, and It won't save my custom actions for batch editing. I want to sign up for the annual most up to date version of photoshop, but not sure ho

  • Stop general entry at Good Receipt level

    Hi, All we know very well that SAP Business One creates Automatic General Entries, but is there any way to stop that automatic general entries at any document like Good Receipt etc.... reply soon please. Regards Ashar Anwer

  • VoWireles design and best practise

    We have 34xAP (1130, 1240) 2x 4402 WLC and 60x7921 with 1.3.3. 1.Is better use WLC 5.2.193.0 or upgrade to 6.0.196.0? 2. Is it possible use WPA2 + AES + CCKM? 3. Which security setting is best for use for 7921 and fast roaming?