Putting a button on a tab like in netbeans

In netbeans, the tabbed panes have buttons on the tabs so that you can close a file right there.
Does anyone know how to do this?
Thanks,
LNMEgo

This question has been asked a lot, and I know I saw a handy solution posted recently - you might try a search on this forum. Inspired by the solution I found, I came up with an implementation that allows you to add an Action (which provides the icon and the behavior) to a JTabbedPane tab. It is an extension of JTabbedPane along with an Icon that presents buttons for the added Actions. It could use a little work, but here's the code:
//     ActionableTabbedPane.java
//     A JTabbedPane that supports an ActionTabIcon.
package whatever.package.actiontabs;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ActionableTabbedPane extends JTabbedPane
     public ActionableTabbedPane()
          super();
          ActionButtonListener abl = new ActionButtonListener();
          addMouseListener(abl);
          addMouseMotionListener(abl);
     public void addTab(String title, Component component, Action action)
          ActionTabIcon icon = new ActionTabIcon();
          icon.addAction(action);
          super.addTab(title, icon, component);
     public void addTab(String title, Component component, Action[] actions)
          ActionTabIcon icon = new ActionTabIcon();
          for (int i=0; i < actions.length; i++)
               icon.addAction(actions);
          super.addTab(title, icon, component);
     private ActionTabIcon findActionTabIconAt(int x, int y)
          int tabNumber = getUI().tabForCoordinate(this, x, y);
          if (tabNumber < 0) return null;
          Icon icon = getIconAt(tabNumber);
          if (icon == null || !(icon instanceof ActionTabIcon)) return null;
          else return (ActionTabIcon)icon;
     private class ActionButtonListener extends MouseInputAdapter
          private ActionTabIcon      nPressedIcon = null;
          public void mousePressed(MouseEvent e)
               int x = e.getX();
               int y = e.getY();
               ActionTabIcon icon = findActionTabIconAt(x, y);
               if (icon != null)
                    nPressedIcon = icon;
                    Rectangle rect = icon.getBounds();
                    icon.showPressed(x - rect.x, y - rect.y);
                    repaint();
          public void mouseReleased(MouseEvent e)
               if (nPressedIcon == null) return;
               nPressedIcon.showReleased();
               nPressedIcon = null;
               repaint();
          public void mouseDragged(MouseEvent e)
               if (nPressedIcon == null) return;
               int x = e.getX();
               int y = e.getY();
               Rectangle rect = nPressedIcon.getBounds();
               nPressedIcon.showDragged(x - rect.x, y - rect.y);
               repaint();
//     ActionTabIcon.java
//     An icon comprised of one or more buttons that can perform an action
//     when clicked. These buttons will be displayed on a tab in a
//     JTabbedPane.
package whatever.package.actiontabs;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class ActionTabIcon extends JPanel implements Icon
     private JButton          oLastPressedButton = null;
     private int          X = 0,
                    Y = 0;
     public ActionTabIcon()
          // I use a custom layout manager here, but you can use BoxLayout
          setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
          setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0));
          setOpaque(false);
     public void addAction(Action action)
          JButton jb = new JButton(action);
          jb.setOpaque(false);
          jb.setBorder(null);
          add(jb);
     public JButton getButtonAt(int x, int y)
          Component[] comps = getComponents();
          for (int i=0; i < comps.length; i++)
               Rectangle r = comps[i].getBounds();
               if (r.contains(x, y))
                    return (JButton)comps[i];
          return null;
     public void showPressed(int x, int y)
          JButton b = getButtonAt(x, y);
          oLastPressedButton = b;
          if (b == null) return;
          b.getModel().setPressed(true);
          b.getModel().setArmed(true);
     public void showDragged(int x, int y)
          if (oLastPressedButton == null) return;
          JButton b = getButtonAt(x, y);
          if (b != oLastPressedButton)
               // disarm the last button
               oLastPressedButton.getModel().setArmed(false);
               oLastPressedButton.getModel().setPressed(false);
          else
               // ensure that the last button is armed
               oLastPressedButton.getModel().setPressed(true);
               oLastPressedButton.getModel().setArmed(true);
     public void showReleased()
          Component[] comps = getComponents();
          for (int i=0; i < comps.length; i++)
               JButton b = (JButton)comps[i];
               if (b != null)
                    b.getModel().setPressed(false);
                    b.getModel().setArmed(false);
     public void paintIcon(Component c, Graphics g, int x, int y)
          this.X = x;
          this.Y = y;
          setSize(getPreferredSize());
          g.translate(x, y);
          paintComponent(g);
          paintChildren(g);
          paintBorder(g);
          g.translate(-x, -y);
     protected void paintChildren(Graphics g)
          Component[] c = getComponents();
          doLayout();
          for (int i=0; i < c.length; i++)
               int x = c[i].getX();
               int y = c[i].getY();
               g.translate(x, y);
               c[i].paint(g);
               g.translate(-x, -y);
     public int getIconWidth()
          return getPreferredSize().width;
     public int getIconHeight()
          return getPreferredSize().height;
     public Rectangle getBounds()
          Dimension d = getPreferredSize();
          return new Rectangle(X, Y, d.width, d.height);
//     app.java
//     A test application for the ActionableTabbedPane
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import whatever.package.actiontabs.*;
public class app extends JFrame
     /////////////////////// Main Method ///////////////////////
     public static void main(String[] args)
          if (!(args != null && args.length > 0 &&
                    args[0].equalsIgnoreCase("-plaf")))
               try { UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName()); }
               catch(Exception ex) { }
          new app();
     private ActionableTabbedPane     oTabs = null;
     public app()
          // Set up the JFrame...
          setTitle("Test app");
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          setSize(400, 300);
          setLocationRelativeTo(null);
          Container c = getContentPane();
          c.setLayout(new BorderLayout());
          // Create some actions for the tabs...
          Icon closeIcon = new ImageIcon("docClose.gif");
          Icon saveIcon = new ImageIcon("docSave.gif");
          Icon savedIcon = new ImageIcon("docSaved.gif");
          CloseAction closer = new CloseAction("close", closeIcon);
          SaveAction saver = new SaveAction("save", saveIcon, savedIcon);
          // closer and saver are duplicated/cloned so that changes
          // to the action's icon affect only the associated tab...
          Action[] acts1 = { closer.duplicate(), saver.duplicate() };
          Action[] acts2 = { closer.duplicate(), saver.duplicate() };
          Action[] acts3 = { closer.duplicate(), saver.duplicate() };
          Action[] acts4 = { closer.duplicate(), saver.duplicate() };
          Action[] acts5 = { closer.duplicate(), saver.duplicate() };
          // Create the tabbed pane and add some tabs with panels...
          oTabs = new ActionableTabbedPane();
          // Can't use scroll tab layout due to a bug in 1.4 which
          // blocks mouse events from reaching our custom buttons...
          // // oTabs.setTabLayoutPolicy(oTabs.SCROLL_TAB_LAYOUT);
          oTabs.addTab("Document 1", createPanel(Color.blue), acts1);
          oTabs.addTab("Document 2", createPanel(Color.gray), acts2);
          oTabs.addTab("Document 3", createPanel(Color.yellow), acts3);
          oTabs.addTab("Document 4", createPanel(Color.white), acts4);
          oTabs.addTab("Document 5", createPanel(Color.green), acts5);
          c.add(oTabs, BorderLayout.CENTER);
          setVisible(true);
     private JPanel createPanel(Color bg)
          JPanel p = new JPanel();
          p.setBackground(bg);
          p.setOpaque(true);
          return p;
     private class CloseAction extends AbstractAction
          public CloseAction(String actionCommand, Icon icon)
               super("", icon);
               this.putValue(ACTION_COMMAND_KEY, actionCommand);
          public void actionPerformed(ActionEvent ae)
               if (ae.getActionCommand().equals("close"))
                    oTabs.remove(oTabs.getSelectedIndex());
               System.out.println("Close button fired");
          public CloseAction duplicate()
               String actionCommand = (String)getValue(ACTION_COMMAND_KEY);
               Icon icon = (Icon)getValue(SMALL_ICON);
               return new CloseAction(actionCommand, icon);
     private class SaveAction extends AbstractAction
          private Icon saveIcon = null;
          private Icon savedIcon = null;
          public SaveAction(String actionCommand, Icon save, Icon saved)
               super("");
               saveIcon = save;
               savedIcon = saved;
               this.putValue(this.SMALL_ICON, saved);
               this.putValue(ACTION_COMMAND_KEY, actionCommand);
          public void actionPerformed(ActionEvent ae)
               // Clicking the save button switches icons (just to demonstrate)
               Icon icon = (Icon)this.getValue(SMALL_ICON);
               if (icon == saveIcon) putValue(SMALL_ICON, savedIcon);
               else putValue(SMALL_ICON, saveIcon);
               System.out.println("Save button fired");
          public SaveAction duplicate()
               String actionCommand = (String)getValue(ACTION_COMMAND_KEY);
               return new SaveAction(actionCommand, saveIcon, savedIcon);

Similar Messages

  • TabbedPanels Tab - How can we put individual images on each tab button?

    Hi,
    How can we put individual propeties (like size, background images etc) in each tab button of TabbedPanels Tab?
    Thanks

    Wow ! Itz amazing !! .... This is what 'm exactly looking for
    Thanks a lot Gramps
    Alin

  • How to include a button in report header like rowspan? &logfile generation?

    I am really new to this form and I have some questions on the APEX HTML DB:
    The project I need to work on is like this: Based on some criteria, I need to do a database lookup. Then in the result, I need to be able to edit the individual record. So far it is no problem. Here comes the part that I am not sure how to handle or if it can be handled.
    1.     We need to have the ability to copy down certain columns value to selected rows. Therefore, a "copy down" button needs to be included right under the column header cell. For example, based on certain criteria, the following product information is returned: product description, serial number, price, category etc. The “COPY DOWN” button needs to be listed right under the “serial number” table header and before the first row of the result, like “rowspan” in html table header. Once you click on “copy down”, the first rows’s serial number will be copied to all selected rows “serial number”. – Can a button be put right under a column header? If so, can I even reference the cell value in javascript?
    2.     Since we are doing the batch update, I need to have the ability to maintain a logfile to include date and time and what information is modified. – Can I generate a logfile from APEX HTML DB?
    I am not sure APEX HTML DB is a good candidate for the above two tasks.
    Your help is greatly appreciated.

    Hi user572980,
    Welcome to APEX... the more you'll do with it, the more you'll like it.
    1) Are you using a Tabbed Form? Or are you in a report? I try to get a better idea what you're trying to do. Did you already have a look at the templates? You can have a template for the report for ex., in that you can adapt like you wish (in your case put a button under the column header).
    You can also reference the cell values, but for that I should know where you're in (form, report). When you click right on the page and have a look at Page Source you see what item (reference) it is.
    2) You can make a logfile yes. Are you using packages to do the batch update? In that you can make some code to store the history. In otherwords, out-of-the-box in APEX I don't think it exists, but with PLSQL you can do it (so also in APEX). For ex. the plsql package stores it in a history table and you built a report on top of that.
    Dimitri

  • 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 do I get Firefox to show jpeg files in the same window/tab like it once did instead of asking me what to do everytime?

    For a long time, whenever I click on a jpeg link in one of my Yahoo groups, the image simply loads in the Firefox window or tab that I'm viewing and I can simply hit the back button to return to the page I was on before. But just recently when I click on a jpeg link, Firefox asks me where I want to download the file and I have to choose between opening another tab, using Windows Photo Viewer, or selecting another program, I believe this is unnecessary and cumbersome. I would like it if Firefox would simply show me the image I'm trying to view in the same window/tab like it used to instead asking me where to download it and/or opening up a new tab when I don't really need it.

    Hi Twistednerve84, <br>
    At the top of the Firefox window, click on the Firefox button and then select Options to access the options window. Go to the Applications Panel and next to 'JPEG image' content type select to use your default application to view images. <br><br>
    You can also find some information here: <br>
    [[Firefox options, preferences and settings]] <br>
    Please report back!

  • In FF 7.0.1, the New Tab button on the Tab Strip disappeared after clicking the Tab Group icon and trying to return, so I'm looking for advice on how to get the New Tab to reappear on the Tab Strip.

    In Windows Vista, FF 7.0.1, I selected the Tab Group button to try it out. However, when I selected the Tab Group button again to close that view, the New Tab button in the Tab Strip no longer appears. I'm requesting help to restore the New Tab button (has the "+" sign on it) on the Tab Strip just to the right of the currently open tabs.

    You can find the New Tab button showing as a '+' on the Tab bar.
    You can open the Customize window and drag the New Tab button that shows as a plus sign (+) from the Tab bar on another toolbar and it will become a regular toolbar button like the New Tab button that you have in Firefox 3 versions.<br />
    Open the Customize window via "View > Toolbars > Customize" or via "Firefox > Options > Toolbar Layout"
    If you can't find the New Tab button then click the "Restore Default Set" button in the Customize window.
    If you want the New Tab button at the far right end of the Tab bar then place a flexible space to the left of it.

  • APEX:How to put dynamic buttons in a Report.

    Hello all,
    I am creating one application in which i want two buttons in every record. I can't put it manually because it should change according to records in a table So Can anyone tell me how to put dynamic buttons in a report.
    Thanks & Regards,
    Jiten Pansara

    Hi Jiten,
    you cannot create buttons in the report, but you can always create link columns with some css class to show it as button.
    So in the both link column report attributes you will have class="button1" and class="button2"
    And in dynamic actions you need to bind the events based on your link column's jquery selector like:
    .button1
    .button2Thanks

  • Accordion widget - put a button to go to next panel

    Hi,
    There is any way to put a button that, if some form's
    requestes are respected, go to next panel?
    I understood this make the next panel appear
    Spry.Widget.Accordion.prototype.openNextPanel = function()
    return this.openPanel(this.getCurrentPanelIndex() + 1);
    but some ting like that (put in the page) doesn't work
    if( validation == true){
    function nextPanel()
    return this.openPanel(this.getCurrentPanelIndex() + 1);
    I need also to disable the function making go to next panel
    on clicking the "label" (So the button will be the only way to
    change panel)

    No one knows?

  • How to call a macro(check for unsaved data) before calling refresh button of EPM TAB

    Hi,
    I want to show a popup message for any unsaved data before USER hit the refresh button on EPM tab.
    I write the macro like as below in module
    Function TestForUnsavedChanges()
        If ActiveWorkbook.Saved = False Then
            If MsgBox("There is unsaved data, save the data otherwise u will loose the data. Do You Want to Save the Data ?", vbYesNo, "Warning") = vbYes Then
            bSave = True
            Else
            bSave = False
            Application.Undo
            End If
        End If
    End Function
    so how to execute this macro before Refresh ?
    Thanking in Advance !!

    Hi Nilesh,
    Try to add this macro under Function BEFORE_REFRESH.
    Hope this helps.
    Regards,
    Astha

  • How can i put FPM Buttons in custom FPM Views.

    Hi,
      How can i put FPM Buttons in custom FPM Views.
      Couldn't locate them in web dynpro layout or FPM Views and application in Portal Content.
    Thanks,

    Hi,
    you should describe a little bit more what you want to do (e.g. navigation buttons or buttons in containers like e.g. in ESS Address). FPM usually has a quite high reusability so button components are often reused. In case there is already a button component that has everything you need you can just use the self-service administrator to add this view to the right perspective in your FPM application. In case you talk about those buttons that are in the Overview screens than those buttons are dynamically generated.
    In case you just want to have your own button then create this button and fire an FPM event from it. You need to add this event to the FPM view configuration in the self-service administrator. Alternatively you can create a button component and reuse it later.

  • SharePoint 2010 - Add a button next to 'I Like it'

    I would like to add a new button next to 'I like it' when clicked it goes to 'http://www.google.com' (for example)
    any help will be appreciated
    Noor

    Hi,
    You could use declarative customization to add new buttons to SP Ribbon -
    here are some references -
    Adding ribbon items into existing tabs/groups (ribbon customization part 2)
    http://www.sharepointnutsandbolts.com/2010/01/adding-ribbon-items-into-existing.html
    Customizing and Extending the SharePoint 2010 Server Ribbon
    http://msdn.microsoft.com/en-us/library/gg552606(v=office.14).aspx
    Default Server Ribbon Customization Locations
    http://msdn.microsoft.com/en-us/library/office/ee537543(v=office.14).aspx
    Declarative Customization of the Server Ribbon
    http://msdn.microsoft.com/en-us/library/ff407268(v=office.14).aspx
    Adding Custom Button to the SharePoint 2010 Ribbon
    http://blogs.msdn.com/b/jfrost/archive/2009/11/06/adding-custom-button-to-the-sharepoint-2010-ribbon.aspx
    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if the reply helps you

  • My iphone screen is not turning on.when i put it on charging it sounds like it is charging but screen remains black.nothing is happening just i listen sound..plzz help

    My iphone screen is not turning on.when i put it on charging it sounds like it is charging but screen remains black.nothing is happening just i listen sound..plzz help...i m using iphone 2g 3.1.3

    Did you already try to reset the phone by holding the sleep and home button until the Apple logo comes back again?
    If this does not help, try to connect in recovery mode, described here: iOS: Unable to restore

  • I dont have a button in my tabs to close it

    there is no close button in my tabs so i cant close them unless i close my browser i can open tabs it has the open button but no close button

    If you mean that the first tab doesn't have a close button then you can add it this way:
    You can set the pref <b>browser.tabs.closeWindowWithLastTab</b> to false on the <b>about:config</b> page to get a close button on the first (only) tab.
    To open the <i>about:config</i> page, type <b>about:config</b> in the location (address) bar and press the "<i>Enter</i>" key, just like you type the url of a website to open a website.<br />
    If you see a warning then you can confirm that you want to access that page.<br />
    See also:
    * http://kb.mozillazine.org/browser.tabs.closeButtons

  • How do I get the startup page with tabs like "tools" etc.?

    == Issue
    ==
    I have another kind of problem with Firefox
    == Description
    ==
    I have re-installed Firefox but how can I get a normal startup page with a normal toolbar (tabs like "Tools", slot for writing web address etc.)?
    == Firefox version
    ==
    3.6.6
    == Operating system
    ==
    Windows Vista
    == User Agent
    ==
    Mozilla/5.0 (Windows; U; Windows NT 6.0; sv-SE; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 ( .NET CLR 3.5.30729)
    == Plugins installed
    ==
    *-np-mswmp
    *The QuickTime Plugin allows you to view a wide variety of multimedia content in Web pages. For more information, visit the QuickTime Web site.
    *NPRuntime Script Plug-in Library for Java(TM) Deploy
    *Adobe PDF Plug-In For Firefox and Netscape "9.3.3"
    *Default Plug-in
    *Shockwave Flash 10.0 r45
    *iTunes Detector Plug-in
    *CANON iMAGE GATEWAY Album Plugin Utility Module
    *Picasa plugin
    *4.0.50524.0
    *Office Live Update v1.5
    *Virtual Earth 3D 4.00090316005 plugin for Mozilla
    *NPWLPG
    *Windows Presentation Foundation (WPF) plug-in for Mozilla browsers
    *Nexus Personal Plug-Ins
    *Voddler Web Plugin
    *Next Generation Java Plug-in 1.6.0_18 for Mozilla browsers

    In Firefox 3.6 and later on Windows you can hide the menu bar via "View > Toolbars" or via the right click context menu on a toolbar.
    Press F10 or press and hold the Alt key down to bring up the menu bar temporarily.
    Go to "View > Toolbars" or right-click the menu bar or press Alt+V T to select which toolbars to show or hide (click on an entry to toggle the state).
    See also [[Menu bar is missing]] and http://kb.mozillazine.org/Toolbar_customization

  • Is there a way to 'Force all Links to be opened in New Tabs ' like Maxthon browser?

    Is there a way to get Firefox to 'Force all Links to be opened in New Tabs, like Maxthon browser does ? I really like this Maxthon feature but hate Maxthon as it has always has and continues to lock up all the time (what a pain!!)
    Hoping Firefox can do this. By the way I know if you right click a link and ask for it to open in a new tab it will. I want it to be automatic.
    Thank you

    Question already asked and answered.
    I gave an AppleScript and an other helper described a scheme relying upon standard features.
    Yvan KOENIG (VALLAURIS, France) jeudi 21 juillet 2011 23:08:28
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8
    Please :
    Search for questions similar to your own
    before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

Maybe you are looking for

  • Problem with controlling Annotations from Excel VBA

    Hi, I have a PDF document that has plenty of sticky notes attached to it. These sticky notes have been added by multiple authors on all pages of the document. I am trying to import the contents of these sticky notes, their author and the page number

  • Chinese word download to excel

    How to download a Chinese character into excel thoru=gh GUI_DOWNLOAD> I have passed the parametr CODE PAGE as '8400'.But still some kunk character is coming.how to do this? Thanks in Advance.

  • Creating Packages from BLOB field contents, line wrap problems

    Good afternoon, we use an in-house developed database-driven update system to update both our databases and filesystems, the system itself performs really well but there is still one problem I can't fix without some expert help: the code of to-be-upd

  • Datatype in Oracle warehouse builder

    I try to create an external table in OWB. because some of my columns are large I like to use clob as a datatype for some of these columns. Is this possible in OWB? I could not to find it in OWB. Or is there any other way to use columns which can hold

  • Implementing surrogate keys in dimensions

    hello, First thing, I'm new to ODI! I am using Oracle data integrator 10.1.3. I have a dimension table 'Dim_Contracts' as target table. The structure is as follows: PK_Dim_Contract Primary key (surrogate key - to be populated from an Oracle database