Close Button in JTabbedPane

Hi everyone!
one short question: how can I add close-Icons to a JTabbedPane? every panel should have a "X" - ImageIcon, so that it can be closed with a mouseclick.
thank you!
Guido

you can pass an icon as a parameter to JTabbedPane.addTab

Similar Messages

  • 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();

  • Button in JTabbedPane tab

    Greetings,
    i'd like to have a button on every tab in JTabbedPane, like close button in NetBeans when you edit the code. By default, you can put an icon only. Do you guys know how to do that?
    thanks in advence.

    If you can wait another couple of months (or if you are willing to use the beta version), you can use the new JTabbedPane features in Java 6 (Mustang). Have a look at the method setTabComponentAt:
    [url http://download.java.net/jdk6/docs/api/javax/swing/JTabbedPane.html#setTabComponentAt(int,%20java.awt.Component)]setTabComponentAt

  • How can i have close option for JTabbedPane.

    In My product I use JTabbedPane for several tabs,so i need an option to close each tab ,currently I have an toolbar close button and menu button,but these two are global options,so how can I have close option in the same tab??

    For a similer problem I did it like this
    I creates a subclass of JPanel called TabPanel which having a BorderLayout and in the North section of it there is a tool bar with close button. And it has a reference to the Parent JTabbedPane.
    When ever the close button is clicked it just call the remove on parent TabbedPane giving itself as the parameter.
    and every tab page added to JTabbedPane is a instance of it or an instance of its subclass.
    I think that you can do things on your own from here....

  • How to avoid the "Save As" dialog when using "Close Button"

    Hello All,
    I am facing a problem while closing a pdf file.
    I am using the following code to Open a pdf file.
    CAcroApp objAcroApp = new AcroAppClass();
    CAcroAVDoc objAVDoc = new AcroAVDoc();
    objAVDoc.Open(C:\\new.pdf,Sample);
    objAcroApp.Show();
    After opening the document I am **** some changes (adding markup) in the file.
    Then I am closing the file using the Close Button and in YES for the save confirmation dialog.
    Here is the problem.
    After giving YES, I am getting a Save As dialog with "Sample.pdf" in the FileName box.
    I am getting this only in Acrobat 9.0.
    When I tried the same in Acrobat 8.0 I didnt get Save As dialog. It saved with out "Save As" dialog in "C:\\new.pdf".
    I need to give the same behavior in both Acrobat 9.0 and 8.0.
    Please help me out to fix this issue. Thanks in advance.
    Regards,
    Mohd Mustafa SK

    In what you have posted, there is no reason it shouldn't work the same way in Acrobat 9. I would recommend that you submit your complete application to developer support.

  • How to suppress Save As dialog when using the Close button on an editable pdf

    Environment: Windows 7, SDK 9, Adobe Acrobat Pro X, Visual Studio 2010 Professional
    Summary: when a document is opened for editing using automation, edited, then closed using the "Close" button, the confirmation dialog appears, "yes" is selected and then the "Save As" dialog appears.  It should save without the "Save As" dialog in the same way it does were the document opened from Adobe Acrobat directly.  My question is, is there any flag to set which governs whether the "Save As" dialog appears as part of the close document process.  It is behaving as if the document is read-only upon close. (it isn't)
    This is how the document is opened from C++:
    if(SUCCEEDED(hr = ::CoCreateInstance(__uuidof(Adobe9::Acrobat::CAcroAVDoc), 0, CLSCTX_ALL, IID_IUnknown, (void**)&pUnk))){
    hr = OleRun(pUnk);
    if (SUCCEEDED(hr)){
    if (SUCCEEDED(hr = pUnk->QueryInterface(&pAVDoc))){
    hr = pAVDoc->Open((BSTR)CComBSTR(strPath), strDocName, &bRet);
    Even when the plugin is removed from the plug_ins\AcrobatSDK directory, the behaviour is the same.
    Another reproduction is running the BasicIacVC sample, commenting out all lines from gAcroPdDoc->Close(); in InitInstance() and returning TRUE.  If an editable document is opened using the sample, edited then closed using the "X" button, the confirmation dialog is followed by a "Save As" dialog as if it were a read-only document which it is not.
    Any suggestions would be appreciated.
    Regards,
    Evan

    Yes, it does.  (as long as the pdf has been opened via a COM interface)

  • Not able to get the minimize maximized and close button and its running with full screen mode.

    Hi
    My Thunderbird is running with ubuntu OS and while using some shortcut key my thunderbird mailbox switched to full screen mode. now i am not able to resize it's view and also not able to see minimize, maximize and close buttons on top left corner.
    Please help me out.
    Thanks

    I'm also running Ubuntu. Not sure how you got there, but you can try a Control-Q to quit. Then restart it and hope in comes back normal.

  • Unexpected performance of Firefox in Windows 7, namely minimize/maximize/close buttons not working and unable to move/resize window.

    I have been using FF for a while now. My main computer was WinXP-32, though I recently bought a new laptop with Win7-64 installed. This problem was never experienced on my WinXP machine.
    Brief description of problem:
    After a time of having FF up and running, the minimize/maximize/restore/close buttons in the top-right no longer work as expected and, if not maximised, I cannot move the window around my desktop nor resize the browser window. When clicked, the buttons will
    rapidly flash on and off continuously without appearing to perform any noticeable function other than temporarily hogging CPU cycles. I've found that clicking (sometimes double clicking) in the main browser window then mousing over the buttons again seems
    to stop them flashing, though does nothing else.
    To minimize/maximize/restore/move/close the window(s), I have to right-click on the relevant tab in my taskbar and pick the desired option. Occasionally, however, even this doesn't work and the right-click menu will disappear as soon as I move the mouse
    over it after right-clicking. 'Show desktop' is a temporary fix for minimising windows and 'ALT + F4' or 'CTRL + W' for closing windows or tabs. This isn't satisfactory and to move or resize a window, I have to close the window in question (sometimes all other
    windows too), reopen it and do what I need to do, though sometimes even this is only a very short fix. If I have to close all the windows, FF will sometimes keep running for a while afterwards, even though no windows are actually open - simply ending the process
    via the windows task manager will fix this though is only a work-around, not a fix.
    One thing I have noticed is that if I manage to move the browser window (when not maximised), for a short period afterwards I can often resize the window successfully. This is more likely to occur if the browser window is not flush with the edge of my screen
    once moved.
    I've tried to include as much information as I can - most of which was determined after several minutes/hours of playing around with different scenarios, trying to manually reproduce particular problems or simply through sheer luck of happening to click
    in the right place at the right time! I hope there is a reasonably fix for this at some point in the not-too-distant future.
    I noticed in some of the threads at another site where people have voiced problems similar to mine, that a link to 'ObjectDock' was discovered in some cases. I do have 'ObjectDock 1.90 Plus' installed on my machine and use it in many ways and so decided
    to see if I could find a connection between the two. I have uninstalled, tested, and reinstalled both programs in a multitude of ways, though could find no conclusive correlation between having both bits of software running or installed at the same time and
    the problems I am experiencing. In my case, at least, this does not appear to be an answer.
    Also, in another thread on this site, someone suggested there might be a link with AVG Anti-Virus Free (I have version 9.0.819) though I've tried uninstalling it and its various add-ons in several different combinations, with no noticeable improvement.
    Sorry for such a long question... If you need to know anything more, just let me know!
    - James
    System Information:
    Operating System: Windows 7 (64 bit)
    Firefox Version: 3.6.3
    Application Basics
    Name
    Firefox
    Version
    3.6.3
    Profile Directory
    <button onclick="openProfileDirectory()"> Open Containing Folder </button>
    Installed Plugins
    about:plugins
    Build Configuration
    about:buildconfig
    Extensions
    Name
    Version
    Enabled
    ID
    Update Service
    1.2
    true
    [email protected]
    Java Console
    6.0.17
    true
    {CAFEEFAC-0016-0000-0017-ABCDEFFEDCBA}
    Adblock Plus
    1.2
    true
    {d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}
    Download Statusbar
    0.9.6.8
    true
    {D4DD63FA-01E4-46a7-B6B1-EDAB7D6AD389}
    Cooliris
    1.11.6
    true
    [email protected]
    FoxTab
    1.3
    true
    {ef4e370e-d9f0-4e00-b93e-a4f274cfdd5a}
    Save File to
    2.0.1
    true
    [email protected]
    1-Click YouTube Video Downloader
    1.4
    true
    [email protected]
    British English Dictionary
    1.19
    true
    [email protected]
    Tab History
    1.0.7
    true
    {84417002-6445-49b4-9fd7-1ef48240fa41}
    Universal Print
    0.4.23
    true
    {BE2100B3-1D80-48eb-ACCF-D26750644378}
    Active Stop Button
    1.3.0
    true
    {9e96e0c4-9bde-49b7-989f-a4ca4bdc90bb}
    Fission
    1.0.9
    true
    {1280606b-2510-4fe0-97ef-9b5a22eafe41}
    Smart Bookmarks Bar
    1.4.3
    true
    [email protected]
    Compact Menu 2
    3.1.1
    true
    {57068FBE-1506-42ee-AB02-BD183E7999E4}
    Menu Editor
    1.2.6
    true
    {EDA7B1D7-F793-4e03-B074-E6F303317FB0}
    Locationbar²
    1.0.5
    true
    [email protected]
    RealPlayer Browser Record Plugin
    1.0
    true
    {ABDE892B-13A8-4d1b-88E6-365A6E755758}
    AVG Safe Search
    9.0.0.812
    true
    {3f963a5b-e555-4543-90e2-c3908898db71}
    Searchbar Autosizer
    1.4.5
    true
    {655397ca-4766-496b-b7a8-3a5b176ee4c2}
    Open Bookmarks in New Tab
    0.1.2010043001
    true
    [email protected]
    Remove New Tab Button
    1.0
    true
    [email protected]
    New Tab Homepage
    0.4.2
    true
    {66E978CD-981F-47DF-AC42-E3CF417C1467}
    SwiftTabs
    0.3.6.8
    true
    {5F4EC95A-FFA8-11DE-898C-667D55D89593}
    Tab Kit
    0.5.8
    true
    [email protected]
    Hide Find Bar
    1.3.1
    true
    [email protected]
    Toolbar Buttons
    0.6.0.8
    true
    {03B08592-E5B4-45ff-A0BE-C1D975458688}
    Java Console
    6.0.19
    true
    {CAFEEFAC-0016-0000-0019-ABCDEFFEDCBA}
    View Cookies
    1.10.1
    true
    {8F6A6FD9-0619-459f-B9D0-81DE065D4E21}
    Adobe DLM (powered by getPlus(R))
    1.6.2.63
    true
    {E2883E8F-472F-4fb0-9522-AC9BF37916A7}
    Modified Preferences
    Name
    Value
    accessibility.typeaheadfind.flashBar
    0
    browser.history_expire_days.mirror
    180
    browser.places.importBookmarksHTML
    false
    browser.places.smartBookmarksVersion
    2
    browser.startup.homepage
    http://www.bath.ac.uk/
    browser.startup.homepage_override.mstone
    rv:1.9.2.3
    browser.tabs.closeButtons
    0
    browser.tabs.tabMinWidth
    77
    browser.tabs.warnOnClose
    false
    extensions.lastAppVersion
    3.6.3
    network.cookie.prefsMigrated
    true
    network.http.pipelining
    true
    network.http.pipelining.maxrequests
    50
    network.http.proxy.pipelining
    true
    places.last_vacuum
    1271706454
    privacy.sanitize.migrateFx3Prefs
    true
    privacy.sanitize.timeSpan
    0
    security.warn_viewing_mixed
    false
    security.warn_viewing_mixed.show_once
    false

    Hi Kossa,
    You can also check if the issue occurs in
    Clean Boot. If the issue disappears in the Clean Boot environment, you can continue to narrow down which entry is causing the issue.
    Besides, uninstall it and re-download
    a fresh copy of FireFox to check the result. If the issue still exists, create a new user account to see if it occurs.
    If the issue persists, you can contact Mozilla Support directly and use Internet Explorer (IE) during the time.
    J
    Please Note: The third-party product discussed here is manufactured by a company that is independent of Microsoft. We make no warranty, implied or otherwise,
    regarding this product's performance or reliability.
    Regards,
    Linda

  • Save and Close button issue in CRM 2013 for Activity Type Appointment

    Hi All,
    Have come across a strange behavior in CRM 2013 and would like  to be sure that it really is an issue which others have encountered too.
    Open a Case record, and click on Activity navigation link to see the Open Activity Associated View. Then try creating an Activity of type Meeting and click on
    Save & Close button (not just Save). When you refresh the view, the activity might show up. But repeat the same steps and create another Activity of Type Meeting and this activity will not show up. It doesnt show up even in the All Activities
    view. Seems like the activity does not get created when using Save and Close button.
    This behavior is replicated even on online 30 day trial version. Any inputs?
    Regards,
    Yogesh

    The problem only occurs when your appointment times clash.   "Save and close" just throws the appointment away.  "Save" tells you about clash (or perhaps it's just unavailability) and allows you to ignore and continue with the
    save.

  • Missing maximize, minimize and close buttons

    I see that people have been having problems with these issues before the finalized FF4, I have the most updated version on my PC. The answers all seem to say it was a problem with beta versions. When I stay online for long periods of time my full screen, minimize and close buttons disappear. I have 2 screens and have found that when I pull a tab to the other screen the buttons reappear with that tab. But all the tabs still on previous screens are still missing. If I pull the whole set of tabs (opened together) I still can not get the buttons to reappear. when I am ready to close all the open tabs at once I use task manager and close down FF4. Right now I see my background screen where the button should be.

    Make sure that you do not run Firefox in full screen mode (press F11 or Fn + F11 to toggle; Mac: Command+Shift+F).
    *https://support.mozilla.org/kb/how-to-use-full-screen
    If you are in full screen mode then hover the mouse to the top of the screen to make the Navigation Toolbar and Tab bar appear.<br>Click the Maximize button (top right corner of the Navigation Toolbar) to leave full screen mode or right-click empty space on a toolbar and choose "Exit Full Screen Mode" or press the F11 key.
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem.
    *Switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance
    *Do NOT click the Reset button on the Safe Mode start window
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    You can also try a different Windows theme.

  • Alert messages from Notification Center hang after using close button

    After opening my MacBook in the morning, Notification Center displays the alerts from my Calender (I realy like this new feature!).
    Problem
    When I click the Close Button on an Alert Message the Alert Message does not close but stops responding and stays displayed.
    The only way to get rid of it is to logout and login to OSX.
    Does anyone have the same problem?
    I am looking for a solution.
    All suggestions are welcome!
    Thanks,
      Chris

    Hi,
    Uploaded with Skitch!
    As you can see the System Preferences > Notification Pane talks about "Alerts" in a general way first
    Then it offers options on how the Notifications are displayed.
    I was presuming you were talking about the Notifications in the same general way and I was asking which option you were using
    Since my first post in this thread I have changes my Mail Notifications to Alerts (It seems to be the one with more issue)
    It does hang around until I deal with it
    It then send me to Mail but the Incoming mail item(s) is(are) no longer marked  as unread.
    This makes it a little difficult to check the generic Inbox rthat has five Accounts set up.
    I am not getting a spinning beach Ball and the Alert Style Notification goes away.
    10:18 PM      Saturday; September 8, 2012
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Lion 10.7.2)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • CRM 2013 - "Save and Close" button behavnig like "Save and New"

    Hi,
    I am working in CRM 2013. I have a scenario in which I am saving new opportunity product record through javascript and preventing original save of CRM. Save is working fine. After save, I need to refresh the screen. So I have used "Xrm.Utility.openEntityForm"
    to open newly created item in edit mode. When I click on "Save and Close" button on this new form in edit mode, instead of closing the opportunity product screen, it opens new entity form. So in short, after saving the record, if I click on "Save
    and Close", it behaves like "Save and New".
    Any one facing such issue?

    Save & Close seems to behave like the Save & "Back" Button, so the form tries to return to the new form, that was opened before.
    But I have no solution for this behavior...

  • How i can dissable/remove close buttons from popup window

    We have an web application so i want to dissable/remove the close button , so please help me as soon as possible.
    we are using only firefox for our web application and also for private use.
    Thank you.

    Just to be sure, you want to '''Remove''' the close button?
    I called the big guys for you.

  • Safari 5.1.2 Tab Close Button on Different Sides in Windows

    I'm not sure if this is unique to my computer(s), but I've noticed that the tab close button is on different sides in the Mac & Windows versions of Safari. On my Mac, the close button is on the Left-Hand side with the tab text centered on the tab. On my Windows, the close button is on the Right-hand side with the tab text justified to the left.
    Why the difference in UI? I do quite a bit of browsing on both computers and I find that I'm constantly having to try to remember where I am to determine where the stupid close button is.
    I've looked around in both the Mac & Windows versions and I can't find an option that specifies where the button is show and whether the text is justified or not.

    OK, here's what I'm talking about. This is a screen capture of a tab from the Macintosh version of Safari:
    Notice how the "X" to close the tab is on the left-hand side and the text of the tab is centered on the width of the tab.
    Here is a screenshot of the Windows version of Safari:
    You can see how the tab is much smaller for one, but also how the text is justified to the left with the "X" to close the tab appearing on the right side of the tab instead of the left.
    I don't really prefer one over the other (ie. left or right side), I just wondered if there's some setting to make them act the same way on both so that I don't have to constantly remember what OS I'm on in order to remember where the darn "X" is to close the tab.

  • Thanks For Your Support in advance i want to know that when I open a website that time view print option and when I click close button then page also new window page also close. I want to copy it how i can stop this print option?

    WHEN I OPEN A URL THAT TIME WITH PAGE OPEN SHOWS PRINT OPTION AND WHEN I CLICK CLOSE BUTTON OF PRINT OPTION THAT TIME NEW WINDOW BUTTON IS CLOSED. I WANT TO CLOSE ONLY PRINT OPTION. PLEASE HELP ME...............THANKS

    Many sites which offer specific "print formatted" pages do that: they assume that once you have finished with the print dialog you no longer want the page itself. So for your convenience they close it. Not so convenient for you, since you still want to view the page.
    I'm not aware of an easy solution for this. I can think of a couple different approaches.
    First, maybe there's an add-on to solve this? That would be easiest.
    Second, maybe there's a userscript to solve this?
    The Greasemonkey add-on runs userscripts which you can copy or download. Be careful to install only long-establish and trusted scripts. (''Is there a site that has this bad behavior that I can view without logging in? I will test one of my existing scripts to see whether it helps.'')
    Third, Firefox has an old system for restricting site permissions in a custom text file in your profile folder (named user.js). Editing this file is a bit advanced, and I haven't been able to test it, but the system works along these lines:
    <br>// Define a policy name for window.close permission
    // (assumes you don't have this pref already)
    user_pref("capability.policy.policynames", "nowindowclose");
    // Define policy: disable sites from using window.close
    // in their scripts
    user_pref("capability.policy.nowindowclose.Window.close", "noAccess");
    // List of sites subject to this policy
    user_pref("capability.policy.nowindowclose.sites", "firstbadsite.com secondbadsite.com");
    Again, I haven't tested that and recommend looking into add-ons first.

Maybe you are looking for