Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / August 2006

Tip: Looking for answers? Try searching our database.

Scrolling the tabs of a JTabbedPane

Thread view: 
WillemF - 07 Aug 2006 11:06 GMT
I have a JTabbedPane implementing a SCROLL_TAB_LAYOUT display option.
I use setSelectedIndex to select a tab that is not being displayed at
a particular instant in time (in other words out-of-range but
accessible
using the scroll arrows). The selection is successful, but the tab is
not brought into the display area. Scrolling to the selected tab
indicates that it has indeed been selected. What can one do to bring
the selected tab into the scroll range when the tab is being selected
programmaticaally using setSelectedIndex? Below is an oldish message on

this BB about a similar problem, but there was, unfortunately, no
reply.
Kind regards, Willem Ferguson

From:        SunDog - view profile
Date:        Thurs, May 8 2003 5:57 pm
Email:         wind_of_f...@earthlink.com (SunDog)
Groups:         comp.lang.java.programmer

Hello,
I am using a JTabbedPane to allow a user to switch between seeing
multiple components.  Due to screen size limitations, there can only
be one row of tabs.  We have working code to add tabs as necessary.

The problem comes when many tabs are already in place (so that
scrolling is active), and then more tabs are added.  I want to set the
new tab to be selected -- which works just fine.  However, the new tab
is not visible until the user presses the scroll-right button to get
to it.

I.e., whichever tabs were visible before adding the new tab are the
same tabs which are visible after setting them.  The new tab is way
off to the right, hidden away where the user can't see it or know that
it's active.  Since our application is targetted at novice computer
users, this is likely to lead to much confusion.

The question is: can I set which tabs are visible in a scrolled
JTabbedPane?  Alternatively, can I set what the leftmost visible tab
is?

Thank you in advance for any help.
Michael Dunn - 08 Aug 2006 19:51 GMT
>I have a JTabbedPane implementing a SCROLL_TAB_LAYOUT display option.
> I use setSelectedIndex to select a tab that is not being displayed at
[quoted text clipped - 37 lines]
>
> Thank you in advance for any help.

works OK in 1.5.0_05
simple (rough) demo

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Testing extends JFrame
{
 JTabbedPane tp = new JTabbedPane();
 public Testing()
 {
   setLocation(300,200);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
   JMenu tabsMenu = new JMenu("Show Tab:");
   MenuItemListener mil = new MenuItemListener();
   for(int x = 0; x < 12; x++)
   {
     JPanel p = new JPanel();
     p.add(new JLabel(""+x));
     String letter = ""+(char)(x+65);
     tp.addTab(letter,p);
     JMenuItem menuItem = new JMenuItem(letter);
     tabsMenu.add(menuItem);
     menuItem.addActionListener(mil);
   }
   JMenuBar menuBar = new JMenuBar();
   menuBar.add(tabsMenu);
   setJMenuBar(menuBar);
   getContentPane().add(tp);
   pack();
 }
 class MenuItemListener implements ActionListener
 {
   public void actionPerformed(ActionEvent ae)
   {
     int selectedTab = (int)(((JMenuItem)ae.getSource()).getActionCommand().charAt(0))-65;
     tp.setSelectedIndex(selectedTab);
   }
 }
 public static void main(String[] args){new Testing().setVisible(true);}
}
WillemF - 09 Aug 2006 07:57 GMT
> works OK in 1.5.0_05
> simple (rough) demo

Thanks very much indeed, Michael.
Willem


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.