Application close icon ('X')

Greetings all,
I am new to this forum and relatively new to Java.
I would like to bind a member function to the application close icon (The 'X' in the upper right hand corner of the applications main window).
Does anyone know how to do this?
Thanks.
JavaRob

I would like to bind a member function to the
application close icon (The 'X' in the upper right
hand corner of the applications main window).
Does anyone know how to do this?Create a WindowAdapter and override the windowClosing event to call the method you want. Then do
Window w = ...
w.addWindowListener(myListener);

Similar Messages

  • X (Close) icon doesn't work

    hi,
    I have one problem now. I tried to make 'X' (Close) icon work (i.e. the dialog window should be closed whenever clicking 'X' icon). I use:
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    but it does not work. Anybody could help me solve this problem? Thanks a lot.
    Jrabi

    Well, it is a part of a large project.
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import java.awt.*;
    import com.klg.jclass.field.*;
    import com.borland.dbswing.*;
    import java.awt.event.*;
    import java.util.*;
    public class CitrixAgent_Wiz extends WizardDialog implements SupportService {
    JPanel basePanel = new JPanel();
    WizardTopPanel topPanel = new WizardTopPanel();
    JPanel contentPanel = new JPanel();
    GridBagLayout gridBagLayout1 = new GridBagLayout();
    CardLayout cardLayout = new CardLayout();
    WizardButtonBar buttonBar = new WizardButtonBar(cardLayout, contentPanel, topPanel);
    JScrollPane jScrollPane3 = new JScrollPane();
    GridBagLayout gridBagLayout7 = new GridBagLayout();
    JTextArea finishLabel = new JTextArea();
    JTextArea finishList = new JTextArea();
    JPanel lastPanel = new JPanel();
    TerminalServicesEnvironmentPanel terminalServicesEnvironmentPanel1 = new TerminalServicesEnvironmentPanel();
    TerminalServicesRemoteControlPanel terminalServicesRemoteControlPanel1 = new TerminalServicesRemoteControlPanel();
    TerminalServicesSessionPanel terminalServicesSessionPanel1 = new TerminalServicesSessionPanel();
    private String[] availableDriveLetters = {"D:", "E:", "F:", "G:", "H:", "I:", "J:", "K:", "L:", "M:", "N:", "O:"};
    private String warning;
    private String warningMessage;
    private String advanced;
    private String defaultUserHomePath;
    private String defaultUserProfilePath;
    public CitrixAgent_Wiz() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    try{
    topPanel.setImage((ImageIcon)Global.imageResources.getDialogIcons().get("CitrixCompany"));
    advanced = Global.getString("WIZARD.TERMINAL.1.ADVANCED");
    warning = Global.getString("WIZARD.TERMINAL.1.WARNING");
    warningMessage = Global.getString("WIZARD.TERMINAL.1.WARNINGMESSAGE");
    catch(Exception e){
    System.out.println("Could not get icon " + e.toString());
    setSize(475, 450);
    String provision = Global.getString("WIZARD.COMMON.PROVISIONFOR");
    topPanel.setCreateLabel(provision);
    private void jbInit() throws Exception {
    this.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0); }
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    basePanel.setLayout(gridBagLayout1);
    contentPanel.setLayout(cardLayout);
    jScrollPane3.setBorder(BorderFactory.createLoweredBevelBorder());
    jScrollPane3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    finishLabel.setLineWrap(true);
    finishLabel.setWrapStyleWord(true);
    finishLabel.setBackground(new Color(212,208,200));
    finishLabel.setEditable(false);
    finishLabel.setText(Global.getString("WIZARD.TERMINAL.4.FINISH"));
    finishList.setDoubleBuffered(true);
    finishList.setBackground(Color.lightGray);
    finishList.setEditable(false);
    terminalServicesRemoteControlPanel1.requireCheckBox.setSelected(true);
    lastPanel.setLayout(gridBagLayout7);
    this.getContentPane().add(basePanel, new PaneConstraints("jPanel1", "jPanel1", PaneConstraints.ROOT, 1.0f));
    basePanel.add(topPanel, new GridBagConstraints(0, 0, 1, 1, 100.0, 5.0
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    basePanel.add(contentPanel, new GridBagConstraints(0, 1, 1, 1, 100.0, 90.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    contentPanel.add(terminalServicesEnvironmentPanel1, "terminalServicesEnvironmentPanel1");
    contentPanel.add(terminalServicesRemoteControlPanel1, "terminalServicesRemoteControlPanel1");
    contentPanel.add(terminalServicesSessionPanel1, "terminalServicesSessionPanel1");
    contentPanel.add(lastPanel, "lastPanel");
    lastPanel.add(finishLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 10, 2, 10), 0, 0));
    lastPanel.add(jScrollPane3, new GridBagConstraints(0, 1, 1, 1, 100.0, 105.0
    ,GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 255));
    jScrollPane3.getViewport().add(finishList, null);
    basePanel.add(buttonBar, new GridBagConstraints(0, 2, 1, 1, 100.0, 5.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    buttonBar.addToActionListener();
    buttonBar.reset();
    public boolean validatePage(){
    int page = buttonBar.getCurrentPanel();
    switch(page){
    case 1: return true;
    return true;
    public void prepareNextPage(){
    int nextPage = buttonBar.getCurrentPanel() + 1;
    if (nextPage == buttonBar.getNumberOfPanels()){
    String environmentResult = terminalServicesEnvironmentPanel1.getReport();
    String remoteResult = terminalServicesRemoteControlPanel1.getReport();
    String sessionResult = terminalServicesSessionPanel1.getReport();
    finishList.setText("" + environmentResult + "\n\n" + remoteResult + "\n" + sessionResult);
    finishList.select(1, 1);
    void jButton2_actionPerformed(ActionEvent e) {
    DirectoryChooser chooser = new DirectoryChooser();
    chooser.show();
    if (chooser.isSuccessfulSelect()){
    String text = chooser.getDirectorySelected();
    void jButton3_actionPerformed(ActionEvent e) {
    DirectoryChooser chooser = new DirectoryChooser();
    chooser.show();
    if (chooser.isSuccessfulSelect()){
    String text = chooser.getDirectorySelected();
    * @return the drive letters available to be mapped
    public String[] getAvailableDriveLetters(){
    return availableDriveLetters;
    * Set the drive letters available to be mapped
    * @param letters an array of drive letters in the format [Character]':'
    public void show(){
    String message = Global.getString("WIZARD.TERMINAL.PROVISION.MESSAGE3");
    PTreeNode node = Global.getCurrentNode();
    super.show();
    public boolean provisionApplication(LicConfig app){
    * @todo provision application contained in LicConfig
    return true;
    public boolean deprovisionApplication(LicConfig app){
    * @todo provision application contained in LicConfig
    return true;
    private String getValue(Hashtable h, String key) {
    if (h.containsKey(key))
    return (String)h.get(key);
    return null;
    public void initPanel(Hashtable properties)
    public JComponent getFirstComponent(){
    int page = buttonBar.getCurrentPanel();
    switch(page){
    case 1:
    return terminalServicesEnvironmentPanel1.logonCheckbox;
    case 2:
         return terminalServicesRemoteControlPanel1.enableRemoteCheckBox;
    case 3:
         return terminalServicesSessionPanel1.endComboBox;
    case 4:
         return null;
    return null;
    public JComponent getLastComponent(){
    int page = buttonBar.getCurrentPanel();
    switch(page){
    case 1:
    return buttonBar;
    case 2:
         return buttonBar;
    case 3:
         return buttonBar;
    case 4:
         return null;
    return null;

  • Why do applications close suddenly ?

    I have lots of questions regarding my IPAD. Any help?
    Why do applications close suddenly ?
    The messages are not working or how can i use it?
    The engine is slow
    I want to download the office ( Word and Excel ) what is the programme name?

    In order...
    Close all your applications. Double tap the Home button to display the multi-tasking bar. Tap and hol one of the icons IN THAT BAR. Tap the red circle with a line through it to close those apps. Always do this when you are closing apps you are not actively using. Check out a video if it is still not clear.
    Messages on iPad is not SMS if that is what you mean. You need an Apple ID and iCloud account to send iMessages to other Apple iOS device users from iPad. See more information here.
    The original iPad is much slower compared to new devices - just like computers. Technology moves very fast these days. Other than upgrade, there is really nothing you can do about it being slow.
    Microsoft makes a native Office iOS application for iPad, but it is usable only for subscribers to their Office 365 service and required iOS 6.1 or later. There are several third-party options that you can find in the iTunes App Store.

  • Hide close icon from taskflow inline popups / process window closure

    Hi OTN,
    I would like to know of there is an opportunity to hide "X" close icon from popup window when I run a taskflow in a popup as an inlineDocument?
    Or what is a preferred way to process user window closure to rollback changes?
    In my current application a user always has Cancel button which sets taskflow return parameter as "Cancel" which is then read by dialog return listener.
    The listener would call Rollback if there is "Cancel" returned.
    But "X" close doesn't set any parameter.
    Maybe I sould set "Cancel" as a default return parameter value? Or the right way is to use finalizer?
    Please, advice me.
    Thanks.
    ADF Fusion Web Application
    JDev 11.1.1.3

    You have to define and apply a custom skin. It is easy, read the documentation here:
    http://download.oracle.com/docs/cd/E14571_01/web.1111/b31973/af_skin.htm#BAJFEFCJ
    You can get detailed description of all the supported skin selectors here:
    http://download.oracle.com/docs/cd/E14571_01/apirefs.1111/e15862/toc.htm#ComponentLevelSelectors
    Note, that <tt>af|dialog::close-icon-style {display:none;}</tt> will affect all the popup dialogs, but not only the taskflow popup windows. If you need to apply it only to taskflow popup windows, then use <tt>af|panelWindow::close-icon-style{ display:none; }</tt>. Have a look at Frank's blog post http://blogs.oracle.com/jdevotnharvest/2010/12/how-to_hide_the_close_icon_for_task_flows_opened_in_dialogs.html.
    Dimitar

  • Capture Close icon event for ADF dynamic UI shell

    I am using Oracle ADF dynamic TAB UI shell template to build
    the application.
    I have two option to close Employee TAB on right side , one
    is “Remove Tab” highlighted in Navigation pane and second is close icon in
    right most corner of tab page.
    Now while closing the tab page I want to invoke one method
    or task. In Remove Tab  I am able to do this by managed Bean (writing the
    method into bean and invoke that method in Command link of Navigation pane).
    But here the challenge is to invoke same method while
    closing the Tab by close icon. Therefore I want to capture the event and call
    this method.
    Please let me know if you can share any idea on this.
    When clicked on Remove tab I am getting popup message
    successfully while changing the name SMITHR from RITESH.

    Hi,
    In this thread you have some ideas
    UI Shell - how to allow ADF Library Bounded Task Flow to close itself

  • TS1538 When surfing or working on my iPad mini, frequently my applications close and it goes the home screen.

    When surfing or working on my iPad mini, frequently my applications close and it goes the home screen.  This problem started about a week ago.  I did do a hard reset.

    Make sure you do not leave a lot of apps open in the iOS multitasking bar.
    Dbl click the Home button, look to see now many apps that are still active in the multitask bar.
    You can safely quit some of these by holding your finger on one app until all the icons wiggle.
    Tap the red dash in the upper left corner to quit each app from running. Then just tap anywhere else on the iPad's screen or single click the Home button to stop the wiggling and close the Multitask bar.
    Good Luck!

  • Error copying application.xml icons: .../bin-release/assets/icons' does not exist

    Hi,
    Whenever I try to export the release build I get error from COmpiler during the process that "Error copying application.xml icons: Resource '/Project_Name/bin-release/assets/icons' does not exist."  I have specified 4 icons in the -app.xml file of sizes 16,32,48,128 which exist in the path specified and files are not corrupt. I have checked and unchecked the compiler directive "Copy non-embedded resources in the Output file" but that has not helped too.
    Can somebody please advise what do I do in this situation?
    We are using
    FB4 with Flex Hero(4.5) SDK and java heap space specified in .ini files is 1224m
    This is somewhat urgent guys...
    Thanks
    Shubhra

    Frank,
    Thank you for your answer. I had not checked (will do so tonight).
    I had considered it adequate to wipe out the entire system directory (thereby wiping out the integrated weblogic server), but perhaps it was not adequate? I did not specify that this is on the integrated server, but that is the case....
    Stuart

  • How to handle the "cancel" button and "close" icon of a popup ?

    Hi,
    I have a popup with "cancel button" and "close icon"(on the top right corner of the popup), I want the same operations to be performed on clicking of any of these two components.
    Is there a way to handle such situation ?
    I read about 2 cases to look into this but they didn't work too well for me.
    1. I read about the "popcancellistener" but that listener is called whenever the popup closes, so suppose I have an "ok button" on the popup to create a record, after the record is created, the popup closes and goes into the "popcancellistener", now the question is "how do we know if it came there because of the 'ok button' or 'some other event'".
    2. I even checked the "DialogListener", now I'm able to distinguish between the 'OK' and 'CANCEL' button in the dialoglistener using the "Dialog.Outcome.ok/cancel", but when a user clicks on the close icon, we do not enter the "DialogListener" at all, so in this case "how do we handle the close icon click event"
    Do let me know if you need any more information from my side.
    Thanks for the help in advance.

    The following mechanism responds to any of the following events: <Esc> key, Close icon ('x'), Cancel button
    JavaScript part:
    function popupClosedListener(event){
                  var source = event.getSource();
                  var popupId = source.getClientId();
                  var params = {};
                  params['popupId'] = popupId;
                  var type = "serverPopupClosed";
                  var immediate = true;
                  AdfCustomEvent.queue(source, type, params, immediate);
    }JSF part:
             <af:popup ....>
                  <af:clientListener method="popupClosedListener"
                                           type="popupClosed"/>
                  <af:serverListener type="serverPopupClosed"
                                          method="#{myBean.serverPopupClosedMetod}"/>
            </af:popup>Finally, Java part:
    public void serverPopupClosedMetod(ClientEvent event){
    }

  • While rendering a project in After Effects CC (Mac) , the application closes half way, saying it quit unexpectedly, Please Help!

    So, I have created a cool project that was a lot of hard work in After Effects CC (Mac), While rendering a project in After Effects CC (Mac) , the application closes half way, saying it quit unexpectedly. Here is the link to an error log which is automatically recorded when After Effects crashes:- After Effects Crash (Mac) - Pastebin.com
    I have tried to render this project at least 5 times, shutting and restarting my computer. Please Help!
    Here is my computer specs if needed;
    Operating System: Mac OS X Mavericks version 10.9.4 (13E28)
    Processor: 2.5GHz Intel Core i5
    Memory: 4GB 1600 MHz DDR3
    Graphics: Intel HD Graphics 4000
    Screen Resolution: 13-inch (1280 x 800)
    Hard Drive: 500GB -- 186.49 GB free space.
    Thanks
    Milan

    Element 3d renders using your graphics card. Unlike After Effects, what GPU you're using matters a lot for Element.
    As it is, you don't really have one.
    You could try rendering an image sequence and then picking up your render where it left off when it crashes, but if a certain frame is just too much for your computer to handle, there's not much we can help with. I'd suggest adding a GPU that Element can use.

  • Application builder  icon disappeared from database home page

    i am wondering , is APPLICATION BUILDER ICON removed from database home page of all users or just mine. please i need help here..

    Do you mean the icon display, or the ability to use the app identified by the icon?
    (If just the display (it shows the empty box), there is a known problem with some images appearing broken. In which case, you can try forcing a reload form the server by adding a 'Shift' to your reload command (eg: use Shift-F5 in I.E. or Shift-Ctrl-R in Firefox)

  • Disable close icon on title bar

    Is it possible to disable the close icon on the title bar (right hand corner) in a swing window?
    Fai.

    Example:
    frameNameHere.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    There is also the option to take away the "window-frame" alltogether with:
    frameNameHere.setUndecorated(true);
    Though if you do that you should probably use the "DO_NOTHING_ON_CLOSE" anyway, since otherwise it can still be closed with Alt F4 for instance.

  • Help with disabling close icon of last opened tab in JTabbedPane

    Hello
    Would someone help me out ? I have 3 tabs opened in a JTabbedPane, each with close icon "X". I am looking for a way to tell my program: if the user closes 2 tabs and only 1 remain, disable the close icon "X" of the last opened tab so that the user is unable to close the last tab. I have searched the forum, most I have run into are how to create the close icon. Would someone give me some insight into how to go about doing this? or if you have come across a forum that discusses this, do please post the link. Also, I am using java 1.6.
    Thanks very much in advance

    On each close, look how many tabs are remaining open in the JTabbedPane (getTabCount).
    If there is only one left, set its close button to invisible. Something like this:
    if (pane.getTabCount() == 1) {
        TabCloseButton tcb = (TabCloseButton) pane.getTabComponentAt(0);
        tcb.getBtClose().setVisible(false);
    }

  • JTabbedPane with close Icons

    Ok, so I was trying to get a JTabbedPane with 'X' icons on each tab. Searched this site, and found no answers, but loads of questions on how to do it. I've done it now, and here's my code.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    * A JTabbedPane which has a close ('X') icon on each tab.
    * To add a tab, use the method addTab(String, Component)
    * To have an extra icon on each tab (e.g. like in JBuilder, showing the file type) use
    * the method addTab(String, Component, Icon). Only clicking the 'X' closes the tab.
    public class JTabbedPaneWithCloseIcons extends JTabbedPane implements MouseListener {
      public JTabbedPaneWithCloseIcons() {
        super();
        addMouseListener(this);
      public void addTab(String title, Component component) {
        this.addTab(title, component, null);
      public void addTab(String title, Component component, Icon extraIcon) {
        super.addTab(title, new CloseTabIcon(extraIcon), component);
      public void mouseClicked(MouseEvent e) {
        int tabNumber=getUI().tabForCoordinate(this, e.getX(), e.getY());
        if (tabNumber < 0) return;
        Rectangle rect=((CloseTabIcon)getIconAt(tabNumber)).getBounds();
        if (rect.contains(e.getX(), e.getY())) {
          //the tab is being closed
          this.removeTabAt(tabNumber);
      public void mouseEntered(MouseEvent e) {}
      public void mouseExited(MouseEvent e) {}
      public void mousePressed(MouseEvent e) {}
      public void mouseReleased(MouseEvent e) {}
    * The class which generates the 'X' icon for the tabs. The constructor
    * accepts an icon which is extra to the 'X' icon, so you can have tabs
    * like in JBuilder. This value is null if no extra icon is required.
    class CloseTabIcon implements Icon {
      private int x_pos;
      private int y_pos;
      private int width;
      private int height;
      private Icon fileIcon;
      public CloseTabIcon(Icon fileIcon) {
        this.fileIcon=fileIcon;
        width=16;
        height=16;
      public void paintIcon(Component c, Graphics g, int x, int y) {
        this.x_pos=x;
        this.y_pos=y;
        Color col=g.getColor();
        g.setColor(Color.black);
        int y_p=y+2;
        g.drawLine(x+1, y_p, x+12, y_p);
        g.drawLine(x+1, y_p+13, x+12, y_p+13);
        g.drawLine(x, y_p+1, x, y_p+12);
        g.drawLine(x+13, y_p+1, x+13, y_p+12);
        g.drawLine(x+3, y_p+3, x+10, y_p+10);
        g.drawLine(x+3, y_p+4, x+9, y_p+10);
        g.drawLine(x+4, y_p+3, x+10, y_p+9);
        g.drawLine(x+10, y_p+3, x+3, y_p+10);
        g.drawLine(x+10, y_p+4, x+4, y_p+10);
        g.drawLine(x+9, y_p+3, x+3, y_p+9);
        g.setColor(col);
        if (fileIcon != null) {
          fileIcon.paintIcon(c, g, x+width, y_p);
      public int getIconWidth() {
        return width + (fileIcon != null? fileIcon.getIconWidth() : 0);
      public int getIconHeight() {
        return height;
      public Rectangle getBounds() {
        return new Rectangle(x_pos, y_pos, width, height);
    }You can also specify an extra icon to put on each tab. Read my comments on how to do it.

    With the following code you'll be able to have use SCROLL_TAB_LAYOUT and WRAP_TAB_LAYOUT. With setCloseIcons() you'll be able to set images for the close-icons.
    The TabbedPane:
    import javax.swing.Icon;
    import javax.swing.JComponent;
    import javax.swing.JTabbedPane;
    import javax.swing.JViewport;
    import javax.swing.SwingUtilities;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.FontMetrics;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import javax.swing.event.EventListenerList;
    import javax.swing.plaf.basic.BasicTabbedPaneUI;
    import javax.swing.plaf.metal.MetalTabbedPaneUI;
    * A JTabbedPane which has a close ('X') icon on each tab.
    * To add a tab, use the method addTab(String, Component)
    * To have an extra icon on each tab (e.g. like in JBuilder, showing the file
    * type) use the method addTab(String, Component, Icon). Only clicking the 'X'
    * closes the tab.
    public class CloseableTabbedPane extends JTabbedPane implements MouseListener,
      MouseMotionListener {
       * The <code>EventListenerList</code>.
      private EventListenerList listenerList = null;
       * The viewport of the scrolled tabs.
      private JViewport headerViewport = null;
       * The normal closeicon.
      private Icon normalCloseIcon = null;
       * The closeicon when the mouse is over.
      private Icon hooverCloseIcon = null;
       * The closeicon when the mouse is pressed.
      private Icon pressedCloseIcon = null;
       * Creates a new instance of <code>CloseableTabbedPane</code>
      public CloseableTabbedPane() {
        super();
        init(SwingUtilities.LEFT);
       * Creates a new instance of <code>CloseableTabbedPane</code>
       * @param horizontalTextPosition the horizontal position of the text (e.g.
       * SwingUtilities.TRAILING or SwingUtilities.LEFT)
      public CloseableTabbedPane(int horizontalTextPosition) {
        super();
        init(horizontalTextPosition);
       * Initializes the <code>CloseableTabbedPane</code>
       * @param horizontalTextPosition the horizontal position of the text (e.g.
       * SwingUtilities.TRAILING or SwingUtilities.LEFT)
      private void init(int horizontalTextPosition) {
        listenerList = new EventListenerList();
        addMouseListener(this);
        addMouseMotionListener(this);
        if (getUI() instanceof MetalTabbedPaneUI)
          setUI(new CloseableMetalTabbedPaneUI(horizontalTextPosition));
        else
          setUI(new CloseableTabbedPaneUI(horizontalTextPosition));
       * Allows setting own closeicons.
       * @param normal the normal closeicon
       * @param hoover the closeicon when the mouse is over
       * @param pressed the closeicon when the mouse is pressed
      public void setCloseIcons(Icon normal, Icon hoover, Icon pressed) {
        normalCloseIcon = normal;
        hooverCloseIcon = hoover;
        pressedCloseIcon = pressed;
       * Adds a <code>Component</code> represented by a title and no icon.
       * @param title the title to be displayed in this tab
       * @param component the component to be displayed when this tab is clicked
      public void addTab(String title, Component component) {
        addTab(title, component, null);
       * Adds a <code>Component</code> represented by a title and an icon.
       * @param title the title to be displayed in this tab
       * @param component the component to be displayed when this tab is clicked
       * @param extraIcon the icon to be displayed in this tab
      public void addTab(String title, Component component, Icon extraIcon) {
        boolean doPaintCloseIcon = true;
        try {
          Object prop = null;
          if ((prop = ((JComponent) component).
                        getClientProperty("isClosable")) != null) {
            doPaintCloseIcon = (Boolean) prop;
        } catch (Exception ignored) {/*Could probably be a ClassCastException*/}
        super.addTab(title,
                     doPaintCloseIcon ? new CloseTabIcon(extraIcon) : null,
                     component);
        if (headerViewport == null) {
          for (Component c : getComponents()) {
            if ("TabbedPane.scrollableViewport".equals(c.getName()))
              headerViewport = (JViewport) c;
       * Invoked when the mouse button has been clicked (pressed and released) on
       * a component.
       * @param e the <code>MouseEvent</code>
      public void mouseClicked(MouseEvent e) {
        processMouseEvents(e);
       * Invoked when the mouse enters a component.
       * @param e the <code>MouseEvent</code>
      public void mouseEntered(MouseEvent e) { }
       * Invoked when the mouse exits a component.
       * @param e the <code>MouseEvent</code>
      public void mouseExited(MouseEvent e) {
        for (int i=0; i<getTabCount(); i++) {
          CloseTabIcon icon = (CloseTabIcon) getIconAt(i);
          if (icon != null)
            icon.mouseover = false;
        repaint();
       * Invoked when a mouse button has been pressed on a component.
       * @param e the <code>MouseEvent</code>
      public void mousePressed(MouseEvent e) {
        processMouseEvents(e);
       * Invoked when a mouse button has been released on a component.
       * @param e the <code>MouseEvent</code>
      public void mouseReleased(MouseEvent e) { }
       * Invoked when a mouse button is pressed on a component and then dragged.
       * <code>MOUSE_DRAGGED</code> events will continue to be delivered to the
       * component where the drag originated until the mouse button is released
       * (regardless of whether the mouse position is within the bounds of the
       * component).<br/>
       * <br/>
       * Due to platform-dependent Drag&Drop implementations,
       * <code>MOUSE_DRAGGED</code> events may not be delivered during a native
       * Drag&Drop operation.
       * @param e the <code>MouseEvent</code>
      public void mouseDragged(MouseEvent e) {
        processMouseEvents(e);
       * Invoked when the mouse cursor has been moved onto a component but no
       * buttons have been pushed.
       * @param e the <code>MouseEvent</code>
      public void mouseMoved(MouseEvent e) {
        processMouseEvents(e);
       * Processes all caught <code>MouseEvent</code>s.
       * @param e the <code>MouseEvent</code>
      private void processMouseEvents(MouseEvent e) {
        int tabNumber = getUI().tabForCoordinate(this, e.getX(), e.getY());
        if (tabNumber < 0) return;
        CloseTabIcon icon = (CloseTabIcon) getIconAt(tabNumber);
        if (icon != null) {
          Rectangle rect= icon.getBounds();
          Point pos = headerViewport == null ?
                      new Point() : headerViewport.getViewPosition();
          Rectangle drawRect = new Rectangle(
            rect.x - pos.x, rect.y - pos.y, rect.width, rect.height);
          if (e.getID() == e.MOUSE_PRESSED) {
            icon.mousepressed = e.getModifiers() == e.BUTTON1_MASK;
            repaint(drawRect);
          } else if (e.getID() == e.MOUSE_MOVED || e.getID() == e.MOUSE_DRAGGED ||
                     e.getID() == e.MOUSE_CLICKED) {
            pos.x += e.getX();
            pos.y += e.getY();
            if (rect.contains(pos)) {
              if (e.getID() == e.MOUSE_CLICKED) {
                int selIndex = getSelectedIndex();
                if (fireCloseTab(selIndex)) {
                  if (selIndex > 0) {
                    // to prevent uncatchable null-pointers
                    Rectangle rec = getUI().getTabBounds(this, selIndex - 1);
                    MouseEvent event = new MouseEvent((Component) e.getSource(),
                                                      e.getID() + 1,
                                                      System.currentTimeMillis(),
                                                      e.getModifiers(),
                                                      rec.x,
                                                      rec.y,
                                                      e.getClickCount(),
                                                      e.isPopupTrigger(),
                                                      e.getButton());
                    dispatchEvent(event);
                  //the tab is being closed
                  //removeTabAt(tabNumber);
                  remove(selIndex);
                } else {
                  icon.mouseover = false;
                  icon.mousepressed = false;
                  repaint(drawRect);
              } else {
                icon.mouseover = true;
                icon.mousepressed = e.getModifiers() == e.BUTTON1_MASK;
            } else {
              icon.mouseover = false;
            repaint(drawRect);
       * Adds an <code>CloseableTabbedPaneListener</code> to the tabbedpane.
       * @param l the <code>CloseableTabbedPaneListener</code> to be added
      public void addCloseableTabbedPaneListener(CloseableTabbedPaneListener l) {
        listenerList.add(CloseableTabbedPaneListener.class, l);
       * Removes an <code>CloseableTabbedPaneListener</code> from the tabbedpane.
       * @param l the listener to be removed
      public void removeCloseableTabbedPaneListener(CloseableTabbedPaneListener l) {
        listenerList.remove(CloseableTabbedPaneListener.class, l);
       * Returns an array of all the <code>SearchListener</code>s added to this
       * <code>SearchPane</code> with addSearchListener().
       * @return all of the <code>SearchListener</code>s added or an empty array if
       * no listeners have been added
      public CloseableTabbedPaneListener[] getCloseableTabbedPaneListener() {
        return listenerList.getListeners(CloseableTabbedPaneListener.class);
       * Notifies all listeners that have registered interest for notification on
       * this event type.
       * @param tabIndexToClose the index of the tab which should be closed
       * @return true if the tab can be closed, false otherwise
      protected boolean fireCloseTab(int tabIndexToClose) {
        boolean closeit = true;
        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        for (Object i : listeners) {
          if (i instanceof CloseableTabbedPaneListener) {
            if (!((CloseableTabbedPaneListener) i).closeTab(tabIndexToClose)) {
              closeit = false;
              break;
        return closeit;
       * The class which generates the 'X' icon for the tabs. The constructor
       * accepts an icon which is extra to the 'X' icon, so you can have tabs
       * like in JBuilder. This value is null if no extra icon is required.
      class CloseTabIcon implements Icon {
         * the x position of the icon
        private int x_pos;
         * the y position of the icon
        private int y_pos;
         * the width the icon
        private int width;
         * the height the icon
        private int height;
         * the additional fileicon
        private Icon fileIcon;
         * true whether the mouse is over this icon, false otherwise
        private boolean mouseover = false;
         * true whether the mouse is pressed on this icon, false otherwise
        private boolean mousepressed = false;
         * Creates a new instance of <code>CloseTabIcon</code>
         * @param fileIcon the additional fileicon, if there is one set
        public CloseTabIcon(Icon fileIcon) {
          this.fileIcon = fileIcon;
          width  = 16;
          height = 16;
         * Draw the icon at the specified location. Icon implementations may use the
         * Component argument to get properties useful for painting, e.g. the
         * foreground or background color.
         * @param c the component which the icon belongs to
         * @param g the graphic object to draw on
         * @param x the upper left point of the icon in the x direction
         * @param y the upper left point of the icon in the y direction
        public void paintIcon(Component c, Graphics g, int x, int y) {
          boolean doPaintCloseIcon = true;
          try {
            // JComponent.putClientProperty("isClosable", new Boolean(false));
            JTabbedPane tabbedpane = (JTabbedPane) c;
            int tabNumber = tabbedpane.getUI().tabForCoordinate(tabbedpane, x, y);
            JComponent curPanel = (JComponent) tabbedpane.getComponentAt(tabNumber);
            Object prop = null;
            if ((prop = curPanel.getClientProperty("isClosable")) != null) {
              doPaintCloseIcon = (Boolean) prop;
          } catch (Exception ignored) {/*Could probably be a ClassCastException*/}
          if (doPaintCloseIcon) {
            x_pos = x;
            y_pos = y;
            int y_p = y + 1;
            if (normalCloseIcon != null && !mouseover) {
              normalCloseIcon.paintIcon(c, g, x, y_p);
            } else if (hooverCloseIcon != null && mouseover && !mousepressed) {
              hooverCloseIcon.paintIcon(c, g, x, y_p);
            } else if (pressedCloseIcon != null && mousepressed) {
              pressedCloseIcon.paintIcon(c, g, x, y_p);
            } else {
              y_p++;
              Color col = g.getColor();
              if (mousepressed && mouseover) {
                g.setColor(Color.WHITE);
                g.fillRect(x+1, y_p, 12, 13);
              g.setColor(Color.black);
              g.drawLine(x+1, y_p, x+12, y_p);
              g.drawLine(x+1, y_p+13, x+12, y_p+13);
              g.drawLine(x, y_p+1, x, y_p+12);
              g.drawLine(x+13, y_p+1, x+13, y_p+12);
              g.drawLine(x+3, y_p+3, x+10, y_p+10);
              if (mouseover)
                g.setColor(Color.GRAY);
              g.drawLine(x+3, y_p+4, x+9, y_p+10);
              g.drawLine(x+4, y_p+3, x+10, y_p+9);
              g.drawLine(x+10, y_p+3, x+3, y_p+10);
              g.drawLine(x+10, y_p+4, x+4, y_p+10);
              g.drawLine(x+9, y_p+3, x+3, y_p+9);
              g.setColor(col);
              if (fileIcon != null) {
                fileIcon.paintIcon(c, g, x+width, y_p);
         * Returns the icon's width.
         * @return an int specifying the fixed width of the icon.
        public int getIconWidth() {
          return width + (fileIcon != null ? fileIcon.getIconWidth() : 0);
         * Returns the icon's height.
         * @return an int specifying the fixed height of the icon.
        public int getIconHeight() {
          return height;
         * Gets the bounds of this icon in the form of a <code>Rectangle<code>
         * object. The bounds specify this icon's width, height, and location
         * relative to its parent.
         * @return a rectangle indicating this icon's bounds
        public Rectangle getBounds() {
          return new Rectangle(x_pos, y_pos, width, height);
       * A specific <code>BasicTabbedPaneUI</code>.
      class CloseableTabbedPaneUI extends BasicTabbedPaneUI {
        * the horizontal position of the text
        private int horizontalTextPosition = SwingUtilities.LEFT;
         * Creates a new instance of <code>CloseableTabbedPaneUI</code>
        public CloseableTabbedPaneUI() {
         * Creates a new instance of <code>CloseableTabbedPaneUI</code>
         * @param horizontalTextPosition the horizontal position of the text (e.g.
         * SwingUtilities.TRAILING or SwingUtilities.LEFT)
        public CloseableTabbedPaneUI(int horizontalTextPosition) {
          this.horizontalTextPosition = horizontalTextPosition;
         * Layouts the label
         * @param tabPlacement the placement of the tabs
         * @param metrics the font metrics
         * @param tabIndex the index of the tab
         * @param title the title of the tab
         * @param icon the icon of the tab
         * @param tabRect the tab boundaries
         * @param iconRect the icon boundaries
         * @param textRect the text boundaries
         * @param isSelected true whether the tab is selected, false otherwise
        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;
          javax.swing.text.View v = getTextViewForTab(tabIndex);
          if (v != null) {
            tabPane.putClientProperty("html", v);
          SwingUtilities.layoutCompoundLabel((JComponent) tabPane,
                                             metrics, title, icon,
                                             SwingUtilities.CENTER,
                                             SwingUtilities.CENTER,
                                             SwingUtilities.CENTER,
                                             //SwingUtilities.TRAILING,
                                             horizontalTextPosition,
                                             tabRect,
                                             iconRect,
                                             textRect,
                                             textIconGap + 2);
          tabPane.putClientProperty("html", null);
          int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
          int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
          iconRect.x += xNudge;
          iconRect.y += yNudge;
          textRect.x += xNudge;
          textRect.y += yNudge;
       * A specific <code>MetalTabbedPaneUI</code>.
      class CloseableMetalTabbedPaneUI extends MetalTabbedPaneUI {
        * the horizontal position of the text
        private int horizontalTextPosition = SwingUtilities.LEFT;
         * Creates a new instance of <code>CloseableMetalTabbedPaneUI</code>
        public CloseableMetalTabbedPaneUI() {
         * Creates a new instance of <code>CloseableMetalTabbedPaneUI</code>
         * @param horizontalTextPosition the horizontal position of the text (e.g.
         * SwingUtilities.TRAILING or SwingUtilities.LEFT)
        public CloseableMetalTabbedPaneUI(int horizontalTextPosition) {
          this.horizontalTextPosition = horizontalTextPosition;
         * Layouts the label
         * @param tabPlacement the placement of the tabs
         * @param metrics the font metrics
         * @param tabIndex the index of the tab
         * @param title the title of the tab
         * @param icon the icon of the tab
         * @param tabRect the tab boundaries
         * @param iconRect the icon boundaries
         * @param textRect the text boundaries
         * @param isSelected true whether the tab is selected, false otherwise
        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;
          javax.swing.text.View v = getTextViewForTab(tabIndex);
          if (v != null) {
            tabPane.putClientProperty("html", v);
          SwingUtilities.layoutCompoundLabel((JComponent) tabPane,
                                             metrics, title, icon,
                                             SwingUtilities.CENTER,
                                             SwingUtilities.CENTER,
                                             SwingUtilities.CENTER,
                                             //SwingUtilities.TRAILING,
                                             horizontalTextPosition,
                                             tabRect,
                                             iconRect,
                                             textRect,
                                             textIconGap + 2);
          tabPane.putClientProperty("html", null);
          int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
          int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
          iconRect.x += xNudge;
          iconRect.y += yNudge;
          textRect.x += xNudge;
          textRect.y += yNudge;
    }The Listener:
    import java.util.EventListener;
    * The listener that's notified when an tab should be closed in the
    * <code>CloseableTabbedPane</code>.
    public interface CloseableTabbedPaneListener extends EventListener {
       * Informs all <code>CloseableTabbedPaneListener</code>s when a tab should be
       * closed
       * @param tabIndexToClose the index of the tab which should be closed
       * @return true if the tab can be closed, false otherwise
      boolean closeTab(int tabIndexToClose);
    }

  • CLOSE icon

    hello,
    i have a problem with event KEY-EXIT
    this event doesn't include the CLOSE icon (right top of all windows)
    and users can exit without execute the code in KEY-EXIT event
    in fact KEY-EXIT is trigger only by the icon exit in the tool bar
    How can I trigger my code on system CLOSE icon????
    Thanks for your help
    @Rosagio
    I work under designer 9i who generate forms 9i

    KEY-EXIT triggers fires only when the "Key" associated with the trigger is pressed or DO_KEY('EXIT_FORM') is executed.
    You can use the WHEN-WINDOW-CLOSED trigger on your window and after you finish the standard processing you have (or not) issue a DO_KEY('EXIT_FORM'); this will simulate the EXIT key bein pressed.
    Tony

  • Inline popup - close icon null pointer issue

    Hi all,
    I have a taskflow which is opened as inline popup dialog. Taskflow is in pageFlowScope.
    The popup has OK, Cancel. On click of OK and Cancel of dialog it returns a value.
    However when I click on Close icon "x" of dialog and return to the calling parent window and try to get the any iterator from the binding container, the iterators are all null.
    I am missing something in my configuration.
    Thanks
    Ajay

    Hi,
    actually clicking teh 'x' does nothing than closing the dialog.
    However when I click on Close icon "x" of dialog and return to the calling parent window and try to get the any iterator from the binding container, the iterators are all null.
    What is the code you use and where and when do you call this code ? And what JDeveloper version are you working with ?
    Frank

Maybe you are looking for

  • IPhone 4 - 4.2 upgrade killed visual voicemail

    *iPhone 4 - 4.2 upgrade killed visual voicemail* Ok, I upgraded to 4.2 and deleted all previous backups, so I know I'm screwed untill the next update. I've synced, backed up, restored from backup and still no "Visual Voicemail". My voicemail only wor

  • The road to **** ...

    ... is paved with the tears of folks who just wanted to upgrade their iMacs! It is as if a demon has come along and possessed our computer. I replaced the PRAM battery and added 512 MB ram within the past six weeks. That went well. In fact, I posted

  • Problem with large tree in 10g

    We have a large tree within a form using 10g. This tree is refreshed quite often and we have found a problem when the user clicks in the tree area before the tree has fully displayed it causes a Java error in our JRE and this causes the whole form to

  • How to make the pic showed on ipod 5th while playing mp3

    can anyone teach me the way as captioned, very appreciate your help.

  • Why doesn't IOS Maps show a map any more?

    So, when I was stuck in New York city for five days last week, I wound up using the new IOS maps app for the first time, on my iphone 4. It worked fine for a day or two... then, for some reason, it stopped loading maps.  It would show a blue dot wher