Tab and back-tab out of a JTable

Hi There,
I have been working for some time on improving the default behaviour of the tab key within editable JTables. It largely works as required now, but I'm stuck on getting back-tab to leave the table if on row 0, col 0. I register tab and back-tab action in the table's ActionMap that looks like this:     
     class TabAction extends AbstractAction {
          public void actionPerformed(ActionEvent e) {
               if (getRowCount() > 0) {
                    int row = getSelectedRow();
                    int column = getSelectedColumn();
                    if (row < 0 || column < 0) {
                         row = 0;
                         column = 0;
                    do {
                         if (++column >= getColumnCount()) {
                              row++;
                              column = 0;
                    } while (row < getRowCount() && ! isCellTabbable(row, column));
                    if (row < getRowCount()) {
                         changeSelection(row, column, false, false);
                    } else {
                         clearSelection();
                         transferFocus();
               } else {
                    transferFocus();
     class BackTabAction extends AbstractAction {
          public void actionPerformed(ActionEvent e) {
               if (getRowCount() > 0) {
                    int row = getSelectedRow();
                    int column = getSelectedColumn();
                    if (row < 0 || column < 0) {
                         row = getRowCount() - 1;
                         column = getColumnCount() - 1;
                    do {
                         if (--column < 0) {
                              row--;
                              column = getColumnCount() - 1;
                    } while (row >= 0 && ! isCellTabbable(row, column));
                    if (row >= 0) {
                         changeSelection(row, column, false, false);
                    } else {
                         clearSelection();
                         transferFocusBackward();
                         KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
                            // fm.upFocusCycle(BTTTable_Editable.this);                         
                         // fm.focusPreviousComponent(BTTTable_Editable.this);
               } else {     
                    // transferFocusBackward();
                    // KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
                       // fm.upFocusCycle(BTTTable_Editable.this);                         
                    // fm.focusPreviousComponent(BTTTable_Editable.this);
     }transferFocus() to go to the next screen component works fine - as long as I callsetFocusTraversalPolicyProvider(true); when I create the JTable.
But the backward traversal just doesn't work - instead it does nothing the first time you press back-tab on row 0 col 0, then if you press it again, focus goes onto the last row/col of the table.
As an alternative, I thought maybe I could call the Ctrl-back-tab action, but I can't find that registered in the action map - can anyone tell me how ctrl-back-tab is called and whether I can call that code directly?
Any ideas?
Thanks,
Tim

Where's the rest of your code? What good does posting
the Actions do if we can't execute your code and see
how you've installed the Actions on the table? Who
knows where the mistake is. It may be in the posted
code or it may be in some other code.Well I assume the Action is registered okay because back-tab within the table works fine, and in fact using a debugger I can see that the focus request code (transferFocusBackward) is being called at the right time. I followed it into that code and it appears that it is picking up the tableCellEditor as the "previous" component which is "why" it isn't working right - not that that helps me to fix it.
Anyway, just to confirm, here is a complete standalone testcase:import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
* <br>
* <br>
* Created on 14/11/2005 by Tim Ryan
public class TabTable extends JTable implements FocusListener {
     protected KeyStroke TAB = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
     protected KeyStroke BACK_TAB = KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
               InputEvent.SHIFT_DOWN_MASK);
     protected KeyStroke LEFT_ARROW = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0);
     protected KeyStroke RIGHT_ARROW = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0);
     public TabTable(Object[][] rowData, Object[] columnNames) {
          super(rowData, columnNames);
          initialise();
     public TabTable() {
          super();
          initialise();
     private void initialise() {
          addFocusListener(this);
          InputMap inMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
          ActionMap actionMap = getActionMap();
          inMap.put(LEFT_ARROW, "None");
          inMap.put(RIGHT_ARROW, "None");
          actionMap.put(inMap.get(TAB), new TabAction());
          actionMap.put(inMap.get(BACK_TAB), new BackTabAction());
          setCellSelectionEnabled(true);
          putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
          setFocusTraversalPolicyProvider(true);
     public void focusGained(FocusEvent e) {
          if (getRowCount() > 0 && getSelectedRow() < 0) {
               editCellAt(0, 0);
               getEditorComponent().requestFocusInWindow();
     public void focusLost(FocusEvent e) {
     public void changeSelection(int row, int column, boolean toggle, boolean extend) {
          super.changeSelection(row, column, toggle, false);
          if (editCellAt(row, column)) {
               getEditorComponent().requestFocusInWindow();
      * This class handles the back-tab operation on the table.
      * It repeatedly steps the selection backwards until the focus
      * ends up on a cell that is allowable (see <code>isCellTabbable()</code>).
      * If already at the end of the table then focus is transferred out
      * to the previous component on the screen.
     class BackTabAction extends AbstractAction {
          public void actionPerformed(ActionEvent e) {
               if (getRowCount() > 0) {
                    int row = getSelectedRow();
                    int column = getSelectedColumn();
                    if (row < 0 || column < 0) {
                         row = getRowCount() - 1;
                         column = getColumnCount() - 1;
                    do {
                         if (--column < 0) {
                              row--;
                              column = getColumnCount() - 1;
                    } while (row >= 0 && ! isCellTabbable(row, column));
                    if (row >= 0) {
                         changeSelection(row, column, false, false);
                    } else {
                         clearSelection();
                         // transferFocusBackward();
                         KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent();
               } else {
                    // transferFocusBackward();
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent();
      * This class handles the tab operation on the table.
      * It repeatedly steps the selection forwards until the focus ends
      * up on a cell that is allowable (see <code>isCellTabbable()</code>).
      * If already at the end of the table then focus is transferred out
      * to the next component on the screen.
     class TabAction extends AbstractAction {
          public void actionPerformed(ActionEvent e) {
               if (getRowCount() > 0) {
                    int row = getSelectedRow();
                    int column = getSelectedColumn();
                    if (row < 0 || column < 0) {
                         row = 0;
                         column = 0;
                    do {
                         if (++column >= getColumnCount()) {
                              row++;
                              column = 0;
                    } while (row < getRowCount() && ! isCellTabbable(row, column));
                    if (row < getRowCount()) {
                         changeSelection(row, column, false, false);
                    } else {
                         clearSelection();
                         transferFocus();
               } else {
                    transferFocus();
      * Some cells can be tabbed to, but are not actually editable.
      * @param row
      * @param column
      * @return
     private boolean isCellTabbable(int row, int column) {
          return (column % 2 == 0);
     public boolean isCellEditable(int row, int column) {
          return (column == 1 || column == 3);
      * @param args
     public static void main(String[] args) {
          JFrame frame = new JFrame("Tables test");
          frame.setName("TablesTest");
          frame.setSize(600, 400);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          JPanel panelMain = new JPanel(new GridBagLayout());
          frame.add(panelMain);
          Object[][] tableData = new Object[2][6];
          Object[] columnHeadings = new Object[] {"H0", "H1", "H2", "H3", "H4", "H5"};
          GridBagConstraints gbc = new GridBagConstraints();
          gbc.anchor = GridBagConstraints.NORTH;
          gbc.insets = new Insets(10, 10, 10, 10);
          JTextField field1 = new JTextField("left", 8);
          field1.setName("left");
          panelMain.add(field1, gbc);
          Dimension tableSize = new Dimension(300, 300);
          BTTTable table3 = new BTTTable_Editable(tableData, columnHeadings);
          table3.setName("Editable");
          JScrollPane scroll3 = new JScrollPane(table3);
          scroll3.setPreferredSize(tableSize);
          panelMain.add(scroll3, gbc);
          JTextField field2 = new JTextField("right", 8);
          field2.setName("right");
          gbc.gridwidth = GridBagConstraints.REMAINDER;
          panelMain.add(field2, gbc);
          frame.setVisible(true);
}I thought it might be the focusGained() code, but commenting that out makes no difference.
And here is the code I would use to go to the
previous component:
KeyboardFocusManager.getCurrentKeyboardFocusManager().
focusPreviousComponent();I tried that too, as you can see from my original post. It gives the same answer.
So the big question is why does the FocusManager think that the "previous" field to the table is an editor component within the table?
Regards,
Tim

Similar Messages

  • App tabs and panoroma wiped out at restart

    Help, where is Firefox/Tools > Options, so that I can try the same thing that you suggested above? There is no such thing as tools under my Firefox menu, nor is there an options under my tools menu. I'm using Firefox 6.0.2. I have this same problem that tab groups and app tabs disappear after restarting my Mac. I do not have the 'clear history' setting turned on, so I don't think that is the problem. Big time sink so far.

    ''App tabs and panorama wiped out at restart:''
    Your question appears to be a continuation of something else, but this is your only post that I see here.
    As you say you found app-tabs are part of your browsing history, so you don't want to wipe that out.
    * http://img232.imageshack.us/img232/4928/clearcachew.png
    It is important to close Firefox properly through File > Exit or "Firefox" button > Exit, since you are on a Mac it may be slightly different. In Windows do not use the "X" in the upper right corner which closes the Window but not necessarily Firefox.
    See item #31 in the following, basically if you don't see what you wanted from the previous session, use your History menu to retrieve previous session and then possibly previously closed windows.
    You can make '''Firefox 6.0.2''' look like Firefox 3.6.*, see numbered '''items 1-10''' in the following topic [http://dmcritchie.mvps.org/firefox/firefox-problems.htm#fx4interface Fix Firefox 4.0 toolbar user interface, problems (Make Firefox 4.0 thru 8.0, look like 3.6)]. ''Whether or not you make changes, you should be aware of what has changed and what you have to do to use changed or missing features.''
    * http://dmcritchie.mvps.org/firefox/firefox-problems.htm#fx4interface
    There is a lot more beyond those first 10 steps listed, if you want to make Firefox more functional.
    '''App-tabs''' can be closed and they can become contaminated with unwanted History within the tab. I would suggest you maintain a folder of bookmarks that you can repopulate your tabs at any time by opening the bookmarks in the folder into tabs. You can use the Multiple tab handler" extension [https://support.mozilla.com/questions/846422
    The '''Multiple Tab Handler''' extension provides lots of features for handling multiple tabs: pinning a selection of tabs (app-tabs), pasting titles & urls in various formats. Closing selected tabs, or all tabs to the right/left. Closing tabs to the right is especially useful if using app-tabs.
    Multiple Tab handler ( 74.8KB download) see my usage notes
    *https://addons.mozilla.org/firefox/addon/multiple-tab-handler/
    *http://dmcritchie.mvps.org/firefox/multiple_tab_handler.txt
    If you want to test out the functionality of anything involving Tabs use this test page. (the strange name is derived from my keyword shortcut to the page is "_")
    * http://dmcritchie.mvps.org/firefox/tab_capacity/001_with_underscore.htm
    <br><small>Please mark "Solved" one answer that will best help others with a similar problem -- hope this was it.</small>

  • New tab and close tab buttons are not enabled

    On firefox page, new tab and close tab buttons are not neabled and right click shows the same functions as not available.

    Try the Firefox SafeMode to see how it works there. <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.0+ 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 />
    ''Don't select anything right now, just use "Continue in SafeMode."''
    ''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
    ''When you figure out what is causing that, please let us know. It might help other user's who have that problem.''

  • Why do units of measurement in paragraph tab and character tab differ?

    Why do units of measurement in paragraph tab and character tab differ?
    In Indesign CC 2014.1 when I set the units for type to be in points and all other measurements apart from strokes to be in mm, why are the units for the paragraph tab also in mm?
    In both Photoshop CC and Illustrator CC, whatever units you assign for type also are used for the paragraph settings, which makes sense.
    I want everything to do with type to be in points and pretty much everything else in mm, yet the only way I can have the paragraph tab units as points is for all measurements to be in points!
    Does this sound right or is something wrong with my Indesign?
    Thanks
    Keith

    Glu Design wrote:
    Ok guys I see. I just wondered why InDesign differed to both Photoshop and Illustrator in this respect.
    Thanks
    Keith
    They are made by Adobe, and Adobe has different teams for different applications.
    Sometimes the same feature in multiple applications is designed slightly differently than the way other teams would handle it.
    This may be down to:
    Time constraints to get the feature in - compared to other top priority items
    Having to make a decision on whether to do it one way or another way - 50/50 type thing
    Due to the limitations of how the program was designed and how the feature ties in with other features etc.
    And many many more programming reasons. It may be the guy doing the photoshop changes wasn't as well versed in typography needs as the indesign guy.
    Who knows - but there are differences in lots of areas between all apps.

  • Workflow tab, Personalization tab and Miniapp tab..???

    Hi
    In PFCG there is a tab called workflow, why is it used for and also let me know the use of personalization tab and miniapps tab...?
    Regards
    Rakesh

    Hi Rakesh,
                  Personalization tab was mostly used to give standard access for end users. Like ouptup devices, Printer type ....   if you need more please look in to the following link.
    This tab is common to both Role and user management.
    [http://help.sap.com/saphelp_46c/helpdata/en/68/cf7db4d2e011d296120000e82de14a/frameset.htm]
                MiniApps is nothing but to use a frequently user sap standared URLs, Commonly used applications stored in the table SW3M_ADMIN. 
    Regards,
    vasantha kumar

  • Parent Tab and Standard Tab set

    What is the difference between above three - i.e. Parent Tab, Standard Tab set?
    I understand Parent Tab is the master level Tab, but not sure what is different between Standard Tab Set and Parent Tab? It seems like interchanging of terminology to me.
    Thanks
    Rich

    Thanks Jari, In the link given, there is a point which I have pasted below.
    6. Go to page “Display Attributes“, Select page template to “Two Level Tabs” and Standard Tab Set, in our example it is “TS1(page 1)”How do i go to this "Display Attributes" page?
    Thanks,
    R

  • What do the 'LOCK TAB and PROTECT TAB' choices on the tab Context menu do?

    Right-click context menu on tabs shows Lock Tab and Protect Tab, but I cannot find any information on what each choice actually does. Can someone explain them to me?

    Those contextual menu items are added by the Tab Mix Plus extension.
    http://tmp.garyr.net/forum/

  • If I open more than one tab and then sign out of a password protected site in one tab, it will log me back in if both tabs are not closed and I return to the site. How do I change this?

    If I open a firefox browser and then I were to open another tab (e-mail for example) which is a password protected website, and then I sign out of my e-mail in the tab and close that tab, I can still access my e-mail without having to re-enter a password by going back to the e-mail website from the brower that is still open.
    ex. If I open google and am looking at something so I open another tab to go to hotmail. I then sign out of my hotmail and go back to the google site. If I then go to hotmail from the google site, even though I have signed out it will take me back into my e-mail unless I have closed all tabs upon signing out.
    Is there a way to make it so that if you sign out in one tab it completely signs you out?

    Make sure that Firefox closes properly to prevent session restore from restoring a crashed session.
    *"Hang at exit": http://kb.mozillazine.org/Firefox_hangs
    *"Firefox hangs when you quit it": https://support.mozilla.org/kb/Firefox+hangs
    Use "Firefox/File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit") to close Firefox if you are currently doing that by clicking the close X on the title bar.

  • If I open a PDF doc in a new tab and then try and close the tab with ctrl-w it will try and close all tabs unless I switch to another tab and back again.

    Running Firefox beta and Adobe Acrobat 10. If I open a PDF document in a new tab, say http://support.avaya.com/css/P8/documents/100146419, and then try and close the tab using ctrl-w, I get the message warning me about closing all tabs. If I switch to another tab and then back to the PDF document and then hit ctrl-w, it will just close that one tab and not all tabs.
    Cheers.

    I've just been playing around and I set dom.ipc.plugins.enabled to true and now it closes the PDF document but not the tab. I have to do ctrl-w again to close the tab. However, leaving that set to true ruins the scroll mouse functionality as Acroread seems to want it all to itself.

  • Tabs and windows grayed out

    i cant save any tabs and windows the option is completely grayed out what do i do also i cant add trouble shooting info because i keep getting a error saying the addon could not be downloaded because of a connection error to support.mozilla.org

    ''animefan01 [[#question-1036856|said]]''
    <blockquote>
    i cant save any tabs and windows the option is completely grayed out what do i do also i cant add trouble shooting info because i keep getting a error saying the addon could not be downloaded because of a connection error to support.mozilla.org
    </blockquote>
    also just checked and the session restore file in program files is missing how do i get a new one

  • Opening pages in new tabs is slow and switches to the new tab and back. How can I stop this?

    I work with a lot of tabs and most of the time, I need pages in new tabs to open fast. Recently, whenever I open a page in a new tab, Firefox goes to the new tab for a second, then back to the tab I was on previously, although I have it set to not automatically go to new tabs. This is slowing me down and I'd really like it to stop. I've even tried just having one tab open.

    How to use multiple iPods, iPads, or iPhones with one computer

  • Newbie, Missing Admin tab and Schedules tab is greyed out

    Hi,
    I am totally new to BI Publisher. I just completed the installation of both Oracle DB 10g and OBIEE 10.1.3.4
    I am following the example in OBE to get started with BI Publisher. However, when I open the BI publisher, I don't see the Admin tab and also the schedules tab is greyed out. Where can I reenable the Admin tab?
    Installation details:
    OBIEE 10.1.3.4 with BI Publisher
    I am accessing the BI publisher from Business Intelligence/BI Publisher
    Username: Administrator
    Or is there another menu tab to perform BIP Admin in this version?
    Thanks,
    Gina

    gmsamia wrote:
    Hi,
    I am totally new to BI Publisher. I just completed the installation of both Oracle DB 10g and OBIEE 10.1.3.4
    I am following the example in OBE to get started with BI Publisher. However, when I open the BI publisher, I don't see the Admin tab and also the schedules tab is greyed out. Where can I reenable the Admin tab?
    Installation details:
    OBIEE 10.1.3.4 with BI Publisher
    I am accessing the BI publisher from Business Intelligence/BI Publisher
    Username: Administrator
    Or is there another menu tab to perform BIP Admin in this version?
    Thanks,
    GinaWelcome to BIP!
    Admin tab: u have to include Admin ID in the XMLP_ADMIN group in the RPD. (i believe u know how to do that)
    Schedule: U have to configure scheduler and start the scheduler service. U need to follow as series of steps for that ...

  • How I can find my original manu bar permanently?I want the forward and back tab included window.now I have a window which only shows latest headlines,most visited,customize links etc.help to get back the basic firefox window.

    I made some changes to have a bigger web page display.but now my window shows only a bar providing some tabs such as newest headlines,most visited,customized links,free hotmail,getting started,windows,windows marketplace and windows media.I want to get back my old window with tabs of back,forward etc. and main menu bar.

    In addition to '''''the-edmeister's''''' reply, for other toolbars, also see:
    *https://support.mozilla.com/en-US/kb/Back+and+forward+or+other+toolbar+items+are+missing

  • My Tabs and Grouped Tabs were lost following reboot and not restored via History.

    I closed Firefox properly and rebooted my computer. When I restarted Firefox, instead of seeing the tabs from the previous session, a window with the message that Video DownloadHelper (add on) Update 4.9.6 had been applied, and the other tabs in the open window were what appear to be my default set stored as my Home Page. All of the previous tabs and the grouped tabs that I was using (and would very much like to have back) were gone. I tried to use History>Restore Previous Session, but it was grayed out so I thought to look again and try History>Recently Closed Windows, but there was nothing available to restore either.

    Step 1 would be to salvage your sessionstore files and make backup copies before exiting Firefox or making any other changes.
    Open your active Firefox profile folder (personal settings folder) using
    Help > Troubleshooting Information > "Show Folder" button
    Copy all files that start with sessionstore to a safe location such as your documents folder.
    If you have not exited Firefox since this happened, try the History menu to re-open closed windows ("Previously closed windows") and within each window, to re-open closed tabs ("Previously closed tabs"). Can you get them back??
    Unfortunately, by default, Firefox only stores 10 "Previously closed tabs" per window and 3 "Previously closed windows." You can find these lists on the History menu. This might be enough for most occasions, but you can increase the number stored.
    (1) In a new tab, type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (2) In the search box above the list, type or paste '''sess''' and pause while the list is filtered
    (3) Double-click the '''browser.sessionstore.max_windows_undo''' preference and enter your preferred number of windows (I have 10).
    (4) Double-click the '''browser.sessionstore.max_tabs_undo''' preference and enter your preferred number of tabs (I have 20).
    If you exited Firefox after the tabs were closed, does the sessionstore.bak file have a promising date/time stamp around that time? If you have exited and restarted Firefox multiple times, it's probably no longer possible to recover the old session data. To keep numerous sessions, you need an extension like Session Manager or Tab Mix Plus.

  • Use different "fx-border-image-source" for first tab and remaining tabs

    Hi,
    I'm using something like this
    .tab {
    -fx-padding: 0px 5px -2px 5px;
    -fx-background-insets: 0 -20 0 0;
    -fx-background-color: transparent;
    -fx-text-fill: #c4d8de;
    -fx-border-image-source: url("images/tab5.png");
    -fx-border-image-slice: 20 20 20 20 fill;
    -fx-border-image-width: 20 20 20 20;
    -fx-border-image-repeat: stretch;
    -fx-font-size: 22px;
    .tab:selected {
    -fx-border-image-source: url("images/tab-selected5.png");
    -fx-text-fill: #333333;
         -fx-background-color: red;*/
    to customize the tab appearance of a TabPane.
    That worked well. But I need to use a different set of images for just the first tab. Does anyone know a way to accomplish that?
    Thanks.

    How can I "fix up" the first tab of tab panes that are created after I "fixed up" the first tab of the initial tab pane?
    My app allows user to create new tab panes at any moment during program execution.Not easy to answer this one.
    The best answer would be to use structural pseudoclasses, but (as David points out), they are not yet implemented.
    The trick here is how to identify the first tab of each tab pane so that it can be styled separately from the other panes.
    Doing the styling without a dynamic lookup is preferrable to using a dynamic lookup (i.e. when the first tab is created give it a specific style, e.g. tab0).
    This is how the charts work, where they set style classes based on series of data, e.g. series0, series1 - this allows you to independently style each series of data.
    However the chart stuff has all of that built into the implementation, whereas the tabs don't. To achieve that you would likely need to go into the TabSkin code (http://openjdk.java.net/projects/openjfx/) find out where and how it generates the Tab nodes and write a custom tab skin or extension of the existing one which assigns a numeric style class to each new tab in a pane (e.g tab0, tab1, etc). In other words, not particularly easy if you are unfamilar with the tab skin implementation. You could log a javafx jira feature request to have those style classes set on tabs - file it here => http://javafx-jira.kenai.com.
    In the meantime a simple alternative is to use the dynamic lookup method in my previous post and a hack such that whenever you add a new tab pane to the scene you do something like the following:
    new Timeline(
      new KeyFrame(
        Duration.millis(50),
        new EventHandler<ActionEvent>() {
          @Override public void handle(ActionEvent arg0) {
            Node tab = newTabPane.lookup(".tab");
            if (tab != null) tab.getStyleClass().add("first-tab");
    ).play();The reason for the Timeline is that I don't really know at what stage the css layout pass is executed. I know that when you initially show the stage and then do a lookup, the css pass seems to have already been done and the lookup will work. But for something that is dynamically added or modified after the scene is displayed - I have no idea when the css layout pass occurs, other than it's some time in the future and not at the time that you add the tabPane to the scene. So, the Timeline introduces a short delay to (hopefully) give the css layout pass time to execute and allow the lookup to work (not return null). Not the best or most efficient solution, but should work for you.

Maybe you are looking for