How to insure selected tabs are visible in JTabbedPane

Hello all,
How can you insure that the selected tab in a JTabbedPane is visible.
Here is the code:
import javax.swing.*;
import java.awt.*;
public class TabbedPaneTest extends JTabbedPane implements Runnable
public TabbedPaneTest()
super(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
} // end TabbedPaneTest constructor
public void run ()
for (int i = 1; i <= 10; i ++)
try
this.addTab(Integer.toString(i), createDefaultPanel (i));
this.getModel().setSelectedIndex(i - 1);
Thread.sleep(3000);
} // end try block
catch (Exception e)
e.printStackTrace();
} // end catch block
} // end for loop
} // end run method
private JPanel createDefaultPanel (int index)
JPanel defaultPanel = new JPanel ();
defaultPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), Integer.toString(index)));
return defaultPanel;
} // end createDefaultPanel method
public static void main (String args [])
JFrame frame = new JFrame ();
TabbedPaneTest tpt = new TabbedPaneTest ();
frame.getContentPane().add(tpt);
frame.setSize(200, 200);
Thread newThread = new Thread (tpt);
newThread.start();
frame.setVisible(true);
} // end main method
} // end TabbedPaneTest class
I've crated a JTabbedPane with the tabLayoutPolicy set to JTabbedPane.SCROLL_TAB_LAYOUT.
If I add enough tabs the scroll buttons appear but the newly adde tab is hidden behind them,
even though I have set the selection index to the added tab. The content of the panel associated
with the tab is visible but the tab itself is hidden.
So the selected tab is hidden behind the scroll buttons.
Any one know how to insure that if a tab is selected it is visible to the user.
Thanks

This is an interesting question so I tried it out. After some poking around to see how Swing does this for mouse clicking (try setting things up so that a tab is only partially visible and then click on the visable part - notice how the whole tab is scrolled into view) I found this:    /**
     * This inner class is marked "public" due to a compiler bug.
     * This class should be treated as a "protected" inner class.
     * Instantiate it only within subclasses of BasicTabbedPaneUI.
    public class TabSelectionHandler implements ChangeListener {
        public void stateChanged(ChangeEvent e) {
            JTabbedPane tabPane = (JTabbedPane)e.getSource();
            tabPane.revalidate();
            tabPane.repaint();
            if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {
                int index = tabPane.getSelectedIndex();
                if (index < rects.length && index != -1) {
                    tabScroller.tabPanel.scrollRectToVisible(rects[index]);
    }Which is called when the selected tab changes. The member theScroller is a private inner class that handles the scrolling tabs. The call to scrollRectToVisible is executed for each of your new tabs. Sometimes when I stopped in the debugger and then continued things worked and your new tab scrolled into view.
So I tried putting your code into a Runnable class and invoked it later:          final int newIndex = i;
          SwingUtilities.invokeLater (new Runnable ()  {
               public void run ()  {
                    addTab(Integer.toString(newIndex), createDefaultPanel (newIndex));
                    getModel().setSelectedIndex(newIndex - 1);
          });But that did not work. That is as far as I got so far and I have to stop now. Perhaps this can inspire someone else to a solution.
IL
PS. I first tried Rammensee's solution and it did not work.
Rammensee, you said you hoped you had it right - perhaps you are close.

Similar Messages

  • I accidently unmarked the book marks tool bar, the tool bar and the menu bar how do i get them back ?becaus now only the tabs are visible and i cant access my features or book marks

    i was getting to know my firefox so i accidentally unmarked the menu bar the book marks tool bar and the tool bar. so now only my tabs are visible and i cant get to any of my add-ons or extensions.
    and even surfing the net has become difficult cause there is almost nothing i can do with a new empty tab.
    how can i get these bars back. i tried taking the cursor up to the thin line above the tabs and the window border but the menu to mark the above mentioned features does not appear any more.
    i tried restarting firefox several times but it didn't work. i even uninstalled and completely downloaded a new version of firefox and installed it but the problem still persists.
    i am operations system is windows XP.

    Firefox 3.6+ versions have a feature to allow the user to hide the Menu bar.
    Hit the '''Alt''' key to temporarily show the Menu bar, then open View > Toolbars and select Menu bar, so it has a check-mark. <br />
    The F10 can also be used on most PC's to temporarily reveal the Menu bar.
    https://support.mozilla.com/en-US/kb/Menu+bar+is+missing

  • How do I select an area on a clip in a timeline and copy and paste it ..

    How do I select an area of a clip in the timeline and copy and paste the video track only, several times on the tracks just above it?
    Thank You in Advance,
    Sebastian

    Select the range selection tool (ggg is the keyboard shortcut), then drag through the clip to select the area you want to copy then paste... it will paste only what's selected.
    Jerry

  • ADF Faces: af:menuTabs - How to set selected tab

    I cannot find any documentation on how to set the selected tab of an af:menuTabs instance.
    Please help.

    Hi,
    the method above works if you manually inserts the menu items into a menu component, but not if you declaratively bind each component to a menu model.
    Following the ADF developer's guide, I created a dynamic menu using menuTabs (Section 11.2 Using dynamic menus for navigation). But somehow I don't get a difference in appearance between the selected and unselected tabs.
    I am also confused with the explanation in the tutorial. It says "The menu model in conjuction with nodeStamp controls whether a menu item is rendered as selected. As described earlier, a menu model is created from a tree model, which contains viewId information for each node. ViewIdPropertyMenuModel, which is an instance of MenuModel, uses the viewId of a node to determine the focus rowKey. Each item in the menu model is stamped based on the current rowKey. As the user navigates and the current viewId changes, the focus path of the model also changes and a new set of items is accessed. MenuModel has a method getFocusRowKey(), which determines which page has focus, and automatically renders a node as selected if the node is on the focus path."
    Any suggestions where I should add code to change the appearance of the selected tab? I am using the default Oracle skin.
    Greetings,
    Birgit

  • How can I select the area I want linked, to other page?

    Hi,
    I have been creating multiple stand alone PDF files with links to various documents within a given PDF.  Up until yesterday I would select the Link Button, move my curser to the top left corner of the area to be selected, press the button and drag a box over the area I want selected.  It worked great.  Then BOOM, all of a sudden when I do that now it will not let me select the area I want, it will show a fixed box that appears to be snapped to a formatting line above or below the area I want.  Is there a setting somewhere that might have changed?
    Davey 

    Make sure you do not have the Snap to Grid option selected.
    In Acrobat 8, it is under the View menu.

  • How to highlight selected tab instead of getting the first tab by defaultly

    Hi All ,
    I had one problem with the Jquery accordian. When I am selecting one tab in Jquery accordian then that tab is not getting highlited.
    By defaultly the first tab is getting highlited or selected. The page for that selected tab is opening but the tab is not opening. By defaultly the first tab in accordian is getting selected.
    Can some one help me on this.
    Thanks & Regards,
    P.Mohan Reddy

    My question is like when we click on the first tab in the accordian then that page will open and in the accordian the 1st tab will be opened and other tabs r closed in the jquery accordian. But in the same way when i am selecting the 2nd tab or other tabs in the accordian then that particular tab is not opening even in that case also the 1st tab is opening and the selected tab is not opening.

  • Why isn't the selected tab title bold in JTabbedPane? How can I make it be?

    The selected tab title of JTabbedPanel is not bold. Is there a simple way to set it to be bold when a tab is selected? Thanks in advance.

    1. Simply use the HTML code in it's text like '<html><b>NameOfThisTab</b></html>'.
    2. Extend the JTabbedPane and fine-tune the font it uses.

  • How to determine selected Tab in runtime

    Hi,
    Is there a workaround to figure out which tab we are currently on in a tab set? This would help dynamically enable/disable some components.
    Thanks
    Manohar

    There is currently no way to let the model know which tab is currently selected.  This would be a nice feature to have in a future release.
    Regards,
    Gerrit

  • How can I select an area of a picture (larger than one pixel) and find the average RGB values of all the pixels contained inside the area?

    I'm analysing the differences between several different images and I would like to select a large area of each (such as with lasso tool) and find the average RGB value of all of the pixels within the selection area made/

    With the selection you could do a copy paste and use the histogram of the new layer set the histogram source to selected layer.  The eye dropper sample size may also to get the average  of a square area around a point.

  • Htmlb_tableview - how to define which columns are visible

    Hello
    i am working on an MVC BSP application that renders to the screen 5 fields.
    Yet in the bsp definition I see it reads pt-requisition-list which has many fields.
    <htmlb:tableView id                  = "requilistTab"
                       headerText          = "<%= controller->tv_header %>"
                       headerVisible       = "true"
                       columnHeaderVisible = "true"
                       table               = "<%= controller->pt_requisition_list %>"
                       design              = "alternating"
                       width               = "100%"
                       visibleRowCount     = "20"
                       footerVisible       = "true"
                       emptyTableText      = "<%= otr(paoc_rcf_ui/no_requi) %>"
                       sort                = "SERVER"
                       onHeaderClick       = "dummy"
                       keyColumn           = "OBJID"
                       iterator            = "<%= controller %>"
                       filter              = "SERVER"
                       visibleFirstRow     = "<%= controller->visible_first_row %>"
                       selectedRowKey      = "<%= controller->selected_record-objid %>"
                       selectionMode       = "SINGLESELECT" />
    My question: how do you tell the bsp what fields to display?
    Thanks in advance
    yuval

    iterator = "<%= controller %>"
    this is what makes controlling the columns visible.
    go to the class (referenced by variable controller) and see the method IF_HTMLB_TABLEVIEW_ITERATOR~GET_COLUMN_DEFINITIONS  to see the coding behind this.
    alternative method to show/hide columns without using iterator.
    page attribute:
    col_control_tab     TYPE     TABLEVIEWCONTROLTAB
    col_wa     TYPE     TABLEVIEWCONTROL
    layout
    <%
      clear col_wa .
      move: 'CARRID' to col_wa-columnname ,
      'This is the title of carrid' to col_wa-title ,
      'LEFT' to col_wa-horizontalalignment ,
       'ICON_PLANE' to col_wa-icon ,
      ' ' to col_wa-encode ,
      ' ' to col_wa-wrapping .
      append col_wa to col_control_tab .
      clear col_wa .
      clear col_wa .
      move: 'CONNID' to col_wa-columnname ,
      '<B>Connection</B>' to col_wa-title ,
      'X' to col_wa-sort ,
       'DESCENDING' to col_wa-preSelectedSortDirection ,
      'mycellclick' to col_wa-ONCELLCLICK ,
      'LEFT' to col_wa-horizontalalignment ,
      'X' to col_wa-encode .
      append col_wa to col_control_tab .
      clear col_wa .
    clear col_wa .
      move: 'FLDATE' to col_wa-columnname ,
      'Price' to col_wa-title ,
      'X' to col_wa-sort ,
      'LEFT' to col_wa-horizontalalignment ,
      ' ' to col_wa-encode .
      append col_wa to col_control_tab .
      clear col_wa .
          %>
    <htmlb:tableView id                  = "tv1"
                           design              = "ALTERNATING"
                           selectionMode       = "MULTISELECT"
                           onRowSelection      = "MYROWSELECTION"
                           table               = "<%= flights %>"
                         columnDefinitions   = "<%= col_control_tab %>"
                           tableLayout         = "AUTO"
                           width               = "50%"
                           columnHeaderVisible = "true"/>
    in this example  columnDefinitions  attribute determins which columns to be shown.

  • How do you make tabs wider in a JTabbedPane?

    Topic. The tapped pane uses vertical tabs. I'd like more space around the tabs, but I don't know how to add it.
    Thanks

    You should be able to do this for all tabbed panes by using:
    UIManager.put("TabbedPane.tabAreaInsets", new Insets(...));If you need it for a specific tabbed pane only, then you would probably need to customize the BasicTabbedPaneUI.

  • How do I select a component on a JTabbedPane?

    Hi,
    my tabbedPane consist of several JTables. How do I distinguish them from one another during runtime? My update-method(query) updates the wrong JTable.
    gmtongar

    Thanks for your reply. I have tried with getSelectedIndex(). But take a look at my code:
    this is the create method:
    public void setTabbedPaneGUI(){
        sqlArtist = sqlCon.sqlArtist() ;
        dualCombo = new DualComboBox(this, sqlArtist) ;
        for(int i = 0; i < 4; i++){           
            if(i == 0)
                sqlQuery = sqlCon.sqlDefaultBandValue() ;           
            else if(i == 1)
                sqlQuery = sqlCon.sqlDefaultReleaseValue() ;           
            else if(i == 2)
                sqlQuery = sqlCon.sqlDefaultTrackValue() ;           
            else if(i == 3)
                sqlQuery = sqlCon.sqlDefaultBandValue() ;
            JPanel panel = new JPanel() ;
            buttonTool = new ButtonTool() ;
            tableClass = new TableClass(this, sqlQuery, i) ;
            bandText = new BandFieldGUI() ;
            panel.setLayout(new BorderLayout()) ;
            panel.add(buttonTool, BorderLayout.WEST) ;
            panel.add(tableClass, BorderLayout.CENTER) ;
            panel.add(bandText, BorderLayout.SOUTH) ;
            if(i == 2)
                panel.add(dualCombo, BorderLayout.NORTH) ;
            tabbedPane.addTab(" ", panel) ;
    }This is the update method on the JFrame:
    public void updateTableClass(String b){
        if(getSelectedIndex() == 2){            
            String ElementB = b ;
            String update = sqlCon.refreshTrackTable(ElementB) ;
            System.out.println(update) ;
            tableClass.updateTable(update) ;
    }And finally, this is the update-method in my TableClass:
    public void updateTable(String u){
        String update = "" ;
        if(index == 2){           
            update = u ;             
        try{       
            tableModel.setQuery(update) ;
        catch(SQLException sqle){
            JOptionPane.showMessageDialog(null, sqle.getMessage(),
            "Error", JOptionPane.ERROR_MESSAGE) ;
    }gmtongar

  • Updating a JTabbedPane's selected tab color dynamically

    Hi
    I have set the selected tab color for my JTabbedPane
    using:
    UIManager.put("TabbedPane.selected", Color.RED);Now I would like to change the color dynamically to green.
    However, just calling:
    UIManager.put("TabbedPane.selected", Color.GREEN);doesn't work.
    It seems that if the JTabbedPane is visible while I change the color through the UIManager, it has no effect.
    On the other hand, all the other JTabbedPanes in my application (which are not visible - in hidden dialogs), are effected.
    How can I effect ALL the JTabbedPanes in my application at the same time?

    Try to call
    SwingUtilities.updateComponentTreeUI(selectedPane);
    best regards
    Stas

  • E-Rec 6.0: How to increase the tabs on Candidate Profile

    Hello,
    I'm trying to find out how to increase the tabs that we see on Candidate Profile. In any clients, only 5 tabs are visible on the profile and for more, the candidate clicks on next to view other tabs and then submit the profile. I searched for all configuration tables and code but could not find any.
    I appreciate if anyone could share this info if they know how to do this.
    Points would be awarded .
    Thank you
    K.

    Hi,
    You can configure the tabs at Technical Settings->User interfaces->Setting for BSP->Flexibilization->Container Sequences.
    if you want to add one tab, you have to define one element for container sequence and then assign it to the container of candidate profile at Modify Container Sequence.
    Best Regards,
    Shaoming

  • How do I select, Copy and paste

    Hello,  I cant figure this out.  I want to remove the hand from the globe.  I have been trying to select the areas next to the hand so I can copy and paste but I can't select on Abobe.
    How do you select the area next to the hand so I can copy and paste to remove the hand?  Thanks in advance

    Surfer,
    I want to remove the hand from the globe.
    Will it not tumble down, then?
    And what about the other hand, on the other side?

Maybe you are looking for

  • Reducing TDMS file size?

    Hello, I'm streaming analogue data acquired at 32 kS/s to disk in 32768 data point writes using TDMS Write.vi . A while back I feel that I saw an article about reducing the size of the TDMS files with some tricks. I think one of them might have been

  • Can't buy songs because credit card processing is out of service.

    I haven't bought music using the itunes store before, I made an account, and when I try to enter my credit card information it says that itunes credit card processsing is temporarily unavailable... but it has been saying this to me for about a month

  • View contents of external display on main display (PIP-style)

    I occasionally connect a TV to my MacBook Pro to watch movies and TV shows.  The problem is that I cannot see the TV from where the computer is located.  The computer must stay in this location in order to remain connected to the external HD and A/V

  • SWCV Mising

    Hi Guys, Am trying to use the below SWCV and namespace for define scenario SAP APPL 6.04 GoodsMovementERPCreateRequestConfirmation_In_V1 http://sap.com/xi/APPL/Global2 But if check in  the SLD for the specified SWCV only above one is omited though it

  • OwnCloud Server 8.1 Released Today - Encryption, Performance, Service Packages

    Hey Spiceheads....next week we've got another webinar (and these are always available on-demand following the event BTW), but this one is with the project lead of Sciebo--22 universities who are taking advantage of federated cloud sharing with ownClo