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 / January 2004

Tip: Looking for answers? Try searching our database.

right aligning tab names

Thread view: 
Chris Gokey - 03 Jan 2004 04:24 GMT
I have a JTabbedPane and add tabs using a vertical tab placement policy
[e.g., jtabpane.setTabPlacement(SwingConstants.RIGHT);]

Unfortunately, as I add tabs (e.g., jtabpane.addTab(tabName, component)), it
centers the tab name in the middle of tab.  I'd like to control this and
right align the placement of these tab names.  

I don't see anything in the API as to how this can be done?  Is it possible?

Chris

--
ak - 03 Jan 2004 11:44 GMT
> Unfortunately, as I add tabs (e.g., jtabpane.addTab(tabName, component)), it
> centers the tab name in the middle of tab.  I'd like to control this and
> right align the placement of these tab names.

try
JTabbedPane.setOrientation(ComponentOrientation.LEFT_TO_RIGHT/ComponentOrien
tation.RIGHT_TO_LEFT);

--

____________

http://reader.imagero.com the best java image reader.
Chris Gokey - 03 Jan 2004 15:27 GMT
Thanks, but no luck.  Didn't see any menthod in JTabbedPane called
setOrientation(...)

I did find this:
   jTabbedPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
   jTabbedPane.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);    

But, this didn't work either.

Chris

>> Unfortunately, as I add tabs (e.g., jtabpane.addTab(tabName, component)),
> it
[quoted text clipped - 3 lines]
> try
> JTabbedPane.setOrientation(ComponentOrientation.LEFT_TO_RIGHT
ComponentOrien
> tation.RIGHT_TO_LEFT);
>
[quoted text clipped - 3 lines]
>
> http://reader.imagero.com the best java image reader.

--
ak - 03 Jan 2004 15:53 GMT
> Thanks, but no luck.  Didn't see any menthod in JTabbedPane called
> setOrientation(...)
>
> I did find this:

jTabbedPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

jTabbedPane.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

yes setComponentOrientation ir right one.

> But, this didn't work either.

then you have to write your own AlignedTabbedPaneUI:

public class AlignedTabbedPaneUI extends BasicTabbedPaneUI {

   public static ComponentUI createUI(JComponent c) {
       return new AlignedTabbedPaneUI ();
   }

       protected void layoutLabel(int tabPlacement,
                              FontMetrics metrics, int tabIndex,
                              String title, Icon icon,
                              Rectangle tabRect, Rectangle iconRect,
                              Rectangle textRect, boolean isSelected ) {
       textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
       SwingUtilities.layoutCompoundLabel((JComponent) tabPane,
                                          metrics, title, icon,
                                          SwingUtilities.CENTER,
                                          SwingUtilities.LEADING, //changed
from CENTER to LEADING
                                          SwingUtilities.CENTER,
                                          SwingUtilities.TRAILING,
                                          tabRect,
                                          iconRect,
                                          textRect,
                                          textIconGap);

       int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
       int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
       iconRect.x += xNudge;
       iconRect.y += yNudge;
       textRect.x += xNudge;
       textRect.y += yNudge;
   }
}

____________

http://reader.imagero.com the best java image reader.
Chris Gokey - 03 Jan 2004 20:23 GMT
That worked!  Looking at this class, it seems like you can have a lot of
control over the layout of the tabs once you study how it puts thing
together.

Thanks again.
Chris

>> Thanks, but no luck.  Didn't see any menthod in JTabbedPane called
>> setOrientation(...)
[quoted text clipped - 48 lines]
>
> http://reader.imagero.com the best java image reader.

--
ak - 03 Jan 2004 20:53 GMT
> That worked!  Looking at this class, it seems like you can have a lot of
> control over the layout of the tabs once you study how it puts thing
> together.

To hardcode text align is just a mistake.
Such things are _properties_ and should be accessible without writing new
ComponentUI.

____________

http://reader.imagero.com the best java image reader.


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.