Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
how to round rectangle in jtabbedpane?
sathiya moorthy
Greenhorn
Posts: 9
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i have jtabbedpane and tabplacement is left ,
now i need the tab(the place i have the tab name only) should round rectangle instead of rect
and the next is i need to set the gap between tabs
can u help me please?
Jerome Simard
Greenhorn
Posts: 1
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all, i finally found a solution to space the tabs of a JTabbedPane.
Here are the modifications i done to the BasicTabbedPaneUI.
Best regards,
Jerome Simard
/** * <pre> * Tabs are bigger (ADDED_TAB_HEIGTH) * Tabs are larger than the title they display (ADDED_TAB_WIDTH) * Tabs are spaced (SPACE_BETWEEN_TAB) * Tabs are gray (TAB_COLOR) * Selected tab is blue (SELECTED_TAB_COLOR) * Tabs title font is white and bold * </pre> * * @author Jerome Simard */ public class MyTabbedPaneUI extends BasicTabbedPaneUI { private static final int ADDED_TAB_HEIGTH = 2; private static final int ADDED_TAB_WIDTH = 10; private static final int SPACE_BETWEEN_TAB = 1; private static final Color TAB_COLOR = Color.GRAY; private static final Color SELECTED_TAB_COLOR = Color.BLUE; public static ComponentUI createUI(JComponent c) { return new MyTabbedPaneUI((JTabbedPane) c); } public MyTabbedPaneUI(JTabbedPane tabbedPane) { // FONT: BOLD tabbedPane.setFont(tabbedPane.getFont().deriveFont(Font.BOLD)); // FONT: WHITE tabbedPane.setForeground(Color.WHITE); // TAB BACKGROUND: BLUE (overrided to gray by paintTabBackground) // the background must be set to blue for the line // below the tabs to be blue, else it is the same // color as the tab background (would be gray) tabbedPane.setBackground(SELECTED_TAB_COLOR); } // overrided to add more space each side of the tab title and spacing between tabs. protected void installDefaults() { super.installDefaults(); // changed to add more space each side of the tab title. tabInsets.left = tabInsets.left + ADDED_TAB_WIDTH; tabInsets.right = tabInsets.right + ADDED_TAB_WIDTH; tabInsets.top = tabInsets.top + ADDED_TAB_HEIGTH; tabInsets.bottom = tabInsets.bottom + ADDED_TAB_HEIGTH; // changed to define the spacing between tabs. selectedTabPadInsets.left = SPACE_BETWEEN_TAB; selectedTabPadInsets.right = SPACE_BETWEEN_TAB; } // overrided to paint the selected tab with a different color. protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { // tabpane background color is not used to paint the unselected tabs // because we wants a different color for the background of the tabs // and the background of the tabpane (the line just below the tabs) g.setColor((!isSelected) ? TAB_COLOR : SELECTED_TAB_COLOR); switch (tabPlacement) { case LEFT: g.fillRect(x + 1, y + 1, w - 1, h - 3); break; case RIGHT: g.fillRect(x, y + 1, w - 2, h - 3); break; case BOTTOM: g.fillRect(x + 1, y, w - 3, h - 1); break; case TOP: default: g.fillRect(x + 1, y + 1, w - 3, h - 1); } } // overrided to add spaces between tabs. protected LayoutManager createLayoutManager() { if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) { return super.createLayoutManager(); } else { /* WRAP_TAB_LAYOUT */ return new TabbedPaneLayout() { protected void padSelectedTab(int tabPlacement, int selectedIndex) { // don't pad only the selected tab, but all the tabs, to space them. for (int i = 0; i < rects.length; i++) { Rectangle selRect = rects[i]; Insets padInsets = getSelectedTabPadInsets(tabPlacement); selRect.x += padInsets.left; selRect.width -= (padInsets.left + padInsets.right); selRect.y -= padInsets.top; selRect.height += (padInsets.top + padInsets.bottom); } } }; } } }
Then set this UI to the tabbedpane:
tabbedPane.setUI(new MyTabbedPaneUI(tabbedPane));
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Change Tab Title?
Rearrange Tabs via Drag and Drop
retrieving values from JTabbedPane
Change Mouse Cursor with JTabbedPane
How to Capture a Tab Click on JTabbedPane
More...