JTabbedPane with one close button for all tabs

Hello,
there have several solutions been posted for JTabbedPane subclasses that provide tabs with icons working as close buttons on each tab. I think this is not user friendly because the user can hit the close button accidentally when selecting a tab. And a "really close?" dialog is clumsy.
Therefore I prefer the Netscape browser style: There's only one close button rightmost of the tabs that closes the selected tab. But I don't have an idea how to achieve this.
Does anyone have a solution or an idea? Thanks in advance for help.

This solution has been posted several times and is not what I wanted. But I rewrote the thing so that
- the close buttons are on the right hand side of each tab so that it is conformant with Eclipse style, and
- the close buttons work only with a left click (see code below).
I just wonder how I can move the text a little bit to the left so that the appearence is a bit more balanced. Can someone help, please?
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
class TabbedPaneCloseButtonUI extends BasicTabbedPaneUI {
    public TabbedPaneCloseButtonUI() {
        super();
    protected void paintTab(
        Graphics g,
        int tabPlacement,
        Rectangle[] rects,
        int tabIndex,
        Rectangle iconRect,
        Rectangle textRect) {
        super.paintTab(g, tabPlacement, rects, tabIndex, iconRect, textRect);
        Rectangle rect = rects[tabIndex];
        g.setColor(Color.black);
        g.drawRect(rect.x + rect.width -19, rect.y + 4, 13, 12);
        g.drawLine(
            rect.x + rect.width -16,
            rect.y + 7,
            rect.x + rect.width -10,
            rect.y + 13);
        g.drawLine(
            rect.x + rect.width -10,
            rect.y + 7,
            rect.x + rect.width -16,
            rect.y + 13);
        g.drawLine(
            rect.x + rect.width -15,
            rect.y + 7,
            rect.x + rect.width -9,
            rect.y + 13);
        g.drawLine(
            rect.x + rect.width -9,
            rect.y + 7,
            rect.x + rect.width -15,
            rect.y + 13);
    protected int calculateTabWidth(
        int tabPlacement,
        int tabIndex,
        FontMetrics metrics) {
        return super.calculateTabWidth(tabPlacement, tabIndex, metrics) + 24;
    protected MouseListener createMouseListener() {
        return new MyMouseHandler();
    class MyMouseHandler extends MouseHandler {
        public MyMouseHandler() {
            super();
        public void mouseReleased(MouseEvent e) {
            int x = e.getX();
            int y = e.getY();
            int tabIndex = -1;
            int tabCount = tabPane.getTabCount();
            for (int i = 0; i < tabCount; i++) {
                if (rects.contains(x, y)) {
tabIndex = i;
break;
     if (tabIndex >= 0 && ! e.isPopupTrigger()) {
Rectangle tabRect = rects[tabIndex];
y = y - tabRect.y;
if ((x >= tabRect.x + tabRect.width - 18)
&& (x <= tabRect.x + tabRect.width - 8)
&& (y >= 5)
&& (y <= 15)) {
tabPane.remove(tabIndex);
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
public class TabbedPaneWithCloseButtons {
JFrame frame;
JTabbedPane tabPane;
public TabbedPaneWithCloseButtons() throws Exception {
frame=new JFrame();
frame.getContentPane().setLayout(new BorderLayout());
tabPane=new JTabbedPane();
tabPane.addTab("test1xxxxxxxxxxxxxx", new JLabel("1"));
tabPane.addTab("test2xxxxxxxxxxxxxxxxxxx", new ImageIcon("images/icon.gif"), new JLabel("2"));
tabPane.addTab("test3xxxxxxxx", new JLabel("3"));
tabPane.setUI(new TabbedPaneCloseButtonUI());
frame.getContentPane().add(tabPane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200,200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main(String[] args) throws Exception {
TabbedPaneWithCloseButtons test=new TabbedPaneWithCloseButtons();

Similar Messages

  • Using Firefox 26. How do I get a close button for each tab at the top of the screen?

    Some time ago, I had a close tab button for each tab on the top of the screen. I want that back. I have no additional add ons and the close tab is set to 1. Changing it to 2 does nothing.

    Do you have installed this extension?
    *Firefox/Tools > Add-ons > Extensions
    If you do not have the extension and also have no need for the feature that it provides then you can ignore this.
    If it works in Safe Mode and in normal mode with all extensions (Firefox/Tools > Add-ons > Extensions) disabled then try to find which extension is causing it by enabling one extension at a time until the problem reappears.
    Close and restart Firefox after each change via "Firefox > Exit" (Windows: Firefox/File > Exit; Mac: Firefox > Quit Firefox; Linux: Firefox/File > Quit)
    You can use one of these to start Firefox in <u>Safe Mode</u>:
    *On Windows, hold down the Shift key while starting Firefox with a double-click on the Firefox desktop shortcut
    *On Mac, hold down the Options key while starting Firefox
    *Help > Restart with Add-ons Disabled
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • JTabbedPane and one Button for all Tabs

    Hello everybody,
    im new here an would say HELLOOO to everyone
    So ive got an issue.
    I am creating in "class A"  tabs for a JTabbedPane. In "class B" i create the JTabbedPane and creat instances of class A and add them to the TabbedPane.
    in Class B i also create a button, for save actions. When i click the button, a method "save()" will be called and read from every tab the Strings out of textfields.
    My problem now is, that it dont work, i call the save method with the instance from the tab, but it dont getText() from the textfield.
    For example:
    //create an instance tab, parameter is the save file
    Tab myTab = new Tab(file);
         //other code
    (Tab)myTab.save(); //here i eclipse cast to Tab automatically
    the save-Method in class A (Tab):
    save() {
    sysout(texfield1.getText)
    BTW how can i highlight code in this forum?

    You can add syntax highlighting by going into the advanced editor, that will add a button for it. Unfortunately there are no quick code tags :/
    After you find the button post your ACTUAL code. not just some random snippet which looks like your code. What you posted doesn't even compile.

  • Can we have one submit button for mutliple report regions querying same tbl

    Hello,
    I have a normal multiple report regions in a page with some editable in those regions, these report regions are querying the same table. Now, Is it possible to have one submit button for all the report regions to update the underlying table data?
    Can anyone please help me out with this one.
    thanks,
    Orton

    First you'll almost certainly need to roll your own - the built-in stuff is fairly basic and more than likely won't help.
    It sounds like your process flow should be something like:
    1) Person clicks button.
    2) You do a select for update in the process to get the loan id and put it in the person's queue. At this point you may want to flag that column as having been assigned so it can't be assigned again.
    3) You then forward them to the form to enter data. Personally I would create my own items and processses and forgo the built-in form stuff but you may be able to use the Automated Row Fetch. If you do your own, you just reference the objects like:
    insert into table
    values(:P1_1, :P1_2, :P1_3)Edit - Another way would be to use a regular form and insert Stop/Start Tables - so it can look like a different section, but it really is just a label. Thats another option.

  • How to create one Oprations button (Create Button Or CreateInsert Button )for all master And Detail block?

              hi
       I have master And Detail with 4 level ,I want to have on operations button for all block in data control .
      (similar to Oracle form toolbar)
    how to do it ?

    Well, if you tell us your jdev version and what exactly you try to do, without just telling us 'as in forms' we might be able to help.
    Most of us don't know how it's done in forms. So be specific when you describe your use case.
    Timo

  • How do I create multiple TEBs with one submit button on one page in Captivate 7

    I've read other posts on this topic (which refer primarily to earlier versions of Captivate) and am still at a loss as to how to put multiple text entry boxes on a page with one submit button. Here's my scenario:
    I am creating test questions.
    Each test question has multiple text entry boxes (for numbers only).
    Student should be able to enter numbers into the textboxes in any order.
    Then there is one Submit button that should initiate validating all the text entries, and move to a scoring page (so I can test it). (What would be best is if this button not only did the above, but also submitted scores to the LMS.  But that is not my question at this time.)
    I'd like this question to be set up as a template so that I can duplicate it, be able to add or delete text boxes and change the values required in the text boxes.  
    Here is an image of a sample question page with multiple TEBs. The yellow boxes tell the student where they need to enter text:
    Any help or direction to help is appreciated!!

    I think the problem here is that Arlhoolie wants all of the different TEBs to behave as if they were part of a single interaction that submits only ONE result to the quiz.  Using multiple TEBs in Captivate means that you have multiple scored objects and therefore multiple results being submitted to the quiz.
    If you want a single Success or Failure result submitted to the quiz based on the results from multiple interactive objects then there really is no simple way to do it.  But you could try using the Infosemantics Interactive Master widget to combine all the TEBs as slave objects that report to the Master Widget, which then reports a single score to the quiz based on the results from the slave objects.
    You can learn more about the Master widget here:
    http://www.infosemantics.com.au/adobe-captivate-widgets/interactive-master
    http://www.infosemantics.com.au/interactivemaster/help
    You can download a free trial version of the widget here:
    http://www.infosemantics.com.au/adobe-captivate-widgets/download-free-trial-widgets
    One caveat you should be aware of is that this widget is not HTML5 compatible.

  • How to get One Selection Screen for all queries?

    Hi Experts,
    I have three queries having selection screens. All the selection screen have the same variables, but the reports are different.
    I have created a workbook having these three queries. Each time when the workbook opens, the three selection screen pops up one after the another. Same values are entered in all the selection screens.
    Now the user wants only one selection screen for all the three reports. Is it possible? I tried but I do not see any way.
    I think there should be some way of getting it done.
    Waiting for your inputs,
    With kind regards,
    Shreeem

    Hi
    If a workbook contains multiple queries that use the same variable, you are prompted to enter the variable values again for each query. To avoid this, set the Display Duplicate Variables Only Once flag.
    Goto Workbook Settings>Under Variables Tab>select Display Duplicate Variables only Once
    http://help.sap.com/saphelp_nw70ehp1/helpdata/EN/54/a493f7256b43698191a2623e5a0532/frameset.htm
    Hope this helps,
    Aparna Duvvuri

  • HT201251 I want to use 30  ipads to run kiosk software in my restaurant. Can I use one Apple ID (and one credit card) for all devices

    I want to use 30  ipads to run kiosk software in my restaurant. Can I use one Apple ID (and one credit card) for all devices?

    Alternatively you can always manage your iPads (does not matter how many) with a single apple id and all reporting to your account under "find my device" service. Keeping an eye on all your units. Additionally as you mentioned these are for your Restaurant you may find the solutions offered by this company who creates apps and hardware for this purpose: http://www.spartakioskpro.com
    Additionally if you expand beyond those 30 iPads to say 300 you will want to enable or plan on MDM as your best option to automate every ipad to use the same profile and app and ios configuration while also keeping a close eye on all of them via online MDM services like: https://meraki.cisco.com/products/systems-manager
    Here is a pic

  • Execute Webdynpro4Abap Application with same ERP-User for all portal-users?

    Hi,
    is it possible to let a Webdynpro4Abap application run with only one ERP-User for all portal-users? Therefore not needing an ERP-license for every portal-user?
    Somekind of mapping maybe?
    Regards
    Jan

    Jan,
    It is possible but it all depends on the type of application .If you want to show same data for all users you can use one user but if data is different for all users then you cannot go with this approach.
    to configure single backend user for your application go to tcode SICF and look for that application and go to logon data tab by double clicking and give one common user details
    Thanks
    Bala Duvvuri

  • When pressing Ctrl+f to find something in a page the Find box remains open until I close it, in ALL tabs I have in the firefox window. How can I make firefox open the Find box ONLY in the tab I am in?

    When pressing Ctrl+f to find something in a page the Find box remains open until I close it, in ALL tabs I have in the firefox window. How can I make firefox open the Find box ONLY in the tab I am in?

    Firefox 4 and later versions save the previous session automatically, so there is no longer need for the dialog asking if you want to save the current session.<br />
    Use "File > Exit" or "Firefox > Exit" (Mac: "Firefox > Quit Firefox") if you want to restore multiple windows.<br />
    You can use "History > Restore Previous Session" to get the previous session at any time.<br />
    You may need to click the orange/gray Firefox button to see History.<br />
    There is also a "Restore Previous Session" button on the default <b>about:home</b> Home page.
    Another possibility is to use:
    * [http://kb.mozillazine.org/Menu_differences Firefox/Tools > Options] > General > Startup: "When Firefox Starts": "Show my windows and tabs from last time"

  • For the first time, I downloaded a podcast in the podcast app by clicking on the cloud icon. Now, every single play button for all of my podcast episodes is grayed out. Why can't I play any of my podcasts any more?

    For the first time, I downloaded a podcast in the podcast app by clicking on the cloud icon. Now, every single play button for all of my podcast episodes is grayed out. Why can't I play any of my podcasts any more?

    Greetings Heather,
    After reading your post, it sounds like you are experiencing an error with the Podcasts app. You may want to consider restarting the device first, and then resetting if that does not work. This article provides detailed instructions for Restarting, and Reseting:
    Turn your iOS device off and on (restart) and reset
    How to restart
    Press and hold the Sleep/Wake button on the top of your device until the red slider appears. Then drag the slider to turn your device completely off.
    After the device turns off, press and hold the Sleep/Wake button again until you see the Apple logo.
    How to reset
    You should reset your device as a last resort and only if you can't restart it.
    To reset, press and hold both the Sleep/Wake and Home buttons for at least 10 seconds, until you see the Apple logo.
    Thank you for contributing to Apple Support Communities,
    BobbyD

  • How to force RH9 to use only one master stylesheet for all Word imports?

    I have set a stylesheet (css) as the default for my RH9 WebHelp project in project settings. When I import Word documents into the project, the edit import setting dialog does not show this stylesheet in the list of available stylesheets for the import.
    What is happening instead is a proliferation of unwanted stylesheets derived from all the imported documents. I then have to manually re-set all the new topics to the master stylesheet.
    How can I stop this, and force RH9 to use only the one master stylesheet for all imports?

    cid:[email protected]
    Hi Peter,
    That’s what I thought I was doing in the Project Settings>Import tab>CSS for Style Mapping selection. Maybe that isn’t what it’s meant to do. It’s just getting annoying having all these unneeded files popping up in the project manager so that I have trouble distinguishing the “real” topics from the extra stuff.
    Michael West | Business Improvement | Aurecon
    Ph: +61 3 8683 1996 | Fax: +61 3 8683 1444 | Mob: 0407 485 228
    Email: [email protected]
    PO Box 321, South Melbourne | VIC 3205 | Australia
    http://www.aurecongroup.com
    http://www.aurecongroup.com/apac/groupentity/

  • Publication using "one database fetch for all recepients" is a failure

    Hi,
    I have created a Publication in *CMC* with Crystal Reports as Source Document. When I schedule it with option " One database fetch per recipient" it is a Success. But while using the option "One database fetch for all recipients" it is a Failure.
    I tried this with Personalization value Parameter as well as Filter. But both combinations throw an error message when used with Reporting Bursting Method "One database fetch for all recipients".
    Anybody who has worked with Publication please let me know in which scenario one can use the Advanced setting:
    Report Bursting Method
    "one database fetch for all recepients"
    Regards,
    Amogh.

    Howard,
    The method I use is to put the connection script in a file outside the web root. Although the file has the same name on both the local and remote servers, the details are specific to that particular connection. Then each page in the website has the following PHP script.
    require_once '../outside_folder/.db.php';
    This method is also more secure than including the connection details inside the web root. Also note that the file name begins with a period and ends with the php extension, both for added security.

  • Publication using 'One database fetch for all recipients' is a Failure

    Hi,
    I have created a Publication in CMC with Crystal Reports as Source Document. When I schedule it with option " One database fetch per recipient" it is a Success. But while using the option "One database fetch for all recipients" it is a Failure.
    I tried this with Personalization value Parameter as well as Filter. But both combinations throw an error message when used with Reporting Bursting Method ""One database fetch for all recipients"".
    Anybody who has worked with Publication please let me know in which scenario one can use the Advanced setting:
    Report Bursting Method
    "one database fetch for all recepients"
    Regards,
    Amogh

    Howard,
    The method I use is to put the connection script in a file outside the web root. Although the file has the same name on both the local and remote servers, the details are specific to that particular connection. Then each page in the website has the following PHP script.
    require_once '../outside_folder/.db.php';
    This method is also more secure than including the connection details inside the web root. Also note that the file name begins with a period and ends with the php extension, both for added security.

  • I downloaded mountain lion on my laptop.  Do I need to do the same on my Desktop and iPad or is the one download good for all 3, and how do I do that if it is?

    I downloaded mountain lion on my laptop.  Do I need to do the same on my Desktop and iPad or is the one download good for all 3, and how do I do that if it is?

    If your desktop computer is one that supports Mountain Lion, you can either download it there or make a bootable jump drive with the installer on it -- assuming you haven't yet used the installer you downloaded to your laptop.
    As for the iPad, it doesn't use the same OS as the Macs do; it uses iOS versions, so Mountain Lion won't work there.

Maybe you are looking for