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);
}

Similar Messages

  • Lock icon along with close icon in recent task list of lollipop

    If anyone knows about what is the meaning of lock icon in recent app list in lollipop of lenovo a7000.

    Thanks everyone!
    I submitted a few bug reports, though even if they say they read ALL of them, and I believe them, I doubt they will do anything about this! I feel so small and powerless with bugs like this against Adobe, I just can't imagine an Adobe guy saying "Hey look maybe we should fix that!". As far as I know, Adobe never updated any of their software through updates, if they ever change something, then they call it "CS5" and so on...
    As for John Nack's blog, I went through it and I'm seeing that loads of people are complaining because of the adjusments panel so I think I won't need to. One of his answers to a similar complaint was:
    "If you only try to use the panel in exactly the same way you used the dialog boxes, you're missing the point. You can now adjust things like opacity, blending mode, layer mask parameters, etc. without darting in and out of dialogs that cover up your document.
    Old habits take time to change, but that can't stand in the way of progress. "
    Now I do see that they believe that this is innovative and we just have to get used to it, but I'm still saying that that panel takes up space in my palettes even when I'm not using it. At least dialogs didn't take up space when they weren't needed. We could make a palette for everything and maybe in the future, Photoshop is just going to be a huge palette, with every single function right in front of your eyes, in case you forget about them... I understand that Photoshop can be confusing for people who are new to it and just want to edit family photos of their dog, but they should privilege Pro users, as Photoshop used to be a Pro tool after all...
    Just think of Pro cameras: They didn't change since their invention! Only consumer cameras (or whatever electronics) change trends all the time making it easier to do complicated things...
    But I might just get used to it, who knows?
    Anyway, it's still full of bugs, even if I do get used to it!

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

  • 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){
    }

  • I have Itunes on my PC with close to 1000 songs. The songs were also on my Ipod. I tried to sync with my Ipad 2 and blew the music away on my Itunes. Can it be retrieved?

    I have Itunes on my PC with close to 1000 songs. The songs were also on my Ipod. I connected my Ipad2 and blew away all of my music. Can the music be retrieved and if so how can i do it? tks

    Sure it can, transfer the songs from your backup that you maintained on an external drive,DVDs,cloud storage solution.
    You didn't have a backup?
    If you purchased them from iTunes, plug in your iPod-once it mounts in iTunes right click on the iPod icon and select transfer purchases.
    If they were not purchased from iTunes-google is your friend.
    PS.
    If files are important to you-always have multiple copies on separate media.

  • 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.

  • JTabbedPane with actionlistener?

    Hi. I need to make a JTabbedPane and have every tab listen to an action (mouse or otherwise). In general, i wrote methods to detach and reattach the pane, and they responde perfectly to a temprorary button I made. What i need to do now is detach a tab when the tab name (where the getTitle would go) is double-clicked, but i cant add an action listener to that part of the tab, because, frankly, i dont know how to edit it, besides changing the title. Is there a way to add a button where the title goes? Thank you.

    Search the forum using "+jtabbedpane +close +icon" to find ideas on this topic.

  • 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

  • JTabbed Pane close icon help

    Hi
    I am trying to create a close icon on my JTabbedPane tabs, so i wrote an closeiconTab class extedning Icon and implements MouseListener, whenever a click is observered, i kill the a tab.
    But this method gives me an arrayoutofbound exception error, after debuggin, i realize my implemention goes against the single thread rule for swings. Anyone know a way around this ???
    I've tried this
        public void mouseClicked( MouseEvent e )
            if( _bounds.contains( e.getX(), e.getY() ) )
                 SwingUtilities.invokeLater(new Runnable() {
                     public void run() {
                          _parentTabbedPane.remove( _tabbedComponent );
        }but it still doesnt work

    does the mouse click call the listener? If so, just call the remove method without the SwingUtilities method part.

  • Close icon display for a Tab(ShowdetailItem)

    Hi,
    I am using the PanelTab with multiple ShowDetailItems. I am giving the close icon provision for the showdetail item. But the close icon is coming only in mouse over.
    I need to display the close always(ShowDetailItem).
    Reg,
    Brahma B

    There is a tutorial for JScrollPane:
    http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html
    It came to my mind that JSplitPane is not using JScrollPane for the two components you add. So perhaps the solution would be to "wrap" both your components to their own JScrollPane before you add them to the split pane.
    Then for those scroll panes I would probably use:
    JScrollPane.setColumnHeaderView(myXCloseButtonInAPanel)
    or
    JScrollPane.setCorner(upperRightCorner, myXCloseButton)
    I don't know if that will work, or how it will look like now that you use the scroll pane's scrollbars instead of the split pane's scroll bar. You have to experiment with it. The scroll pane's should be able to resize themself to fit in the split panes areas when you move the divider, and maybe that's not so easy to do. Otherwise you will end up with both a scrollbar from the split pane and a scroll bar from the scroll pane.. yuck.
    Maybe someone else has a better solution?

  • Folders always shown with big icons. I want small ones!

    Hi!
    I have an issue when I open new folders.
    The window always shows the big, messy icons without any order.
    I want all folders to be shown with small icons, in order.
    When I set the settings for finder, and check "open new windows in column view", I can't seem to get it to work for all folders.
    Any ideas?

    Hi Gablug,
    Finder in Tiger needs its settings to be done one by one.
    Firstly,
    close all Finder windows.
    now,
    click Finder's icon in Dock so it opens a Finder window.
    ) set it to Column view
    ) close it
    ) reopen it
    (it should now open in column view)
    ) set its position on screen
    ) close it
    ) reopen it
    (it should now open in column view at the desired location on screen)
    ) resize it
    ) close it
    ) reopen it
    (it should now open with all your favorite settings)
    ) open Finder Preferences, uncheck "always open new windows in column view", and check it back.
    OK now,
    your existing folders.
    You'll have to set them one by one the way described above.
    reason why they open in icon view, is that it was your original setting that they remember until now.
    When you set them one by one, don't forget that you have to close window between each setting in order for Finder to remember it.

  • Setting Close icon (X) for a container

    Hi,
    I just want to know whether it is possible to set close icon (X) for a panel or any other component. Here close icon mean the one which we see on the top right cornet of a IE window.
    Thanks in advance.
    Sapna

    There is a tutorial for JScrollPane:
    http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html
    It came to my mind that JSplitPane is not using JScrollPane for the two components you add. So perhaps the solution would be to "wrap" both your components to their own JScrollPane before you add them to the split pane.
    Then for those scroll panes I would probably use:
    JScrollPane.setColumnHeaderView(myXCloseButtonInAPanel)
    or
    JScrollPane.setCorner(upperRightCorner, myXCloseButton)
    I don't know if that will work, or how it will look like now that you use the scroll pane's scrollbars instead of the split pane's scroll bar. You have to experiment with it. The scroll pane's should be able to resize themself to fit in the split panes areas when you move the divider, and maybe that's not so easy to do. Otherwise you will end up with both a scrollbar from the split pane and a scroll bar from the scroll pane.. yuck.
    Maybe someone else has a better solution?

  • A component within JTabbedPane with overlay layout

    Hi, I use the following solution to have a component within the upper right corner of the JTabbedPane: [http://forums.sun.com/thread.jspa?forumID=57&threadID=636289&start=2|http://forums.sun.com/thread.jspa?forumID=57&threadID=636289&start=2] . It works great, but when I'm resizing a window with the JTabbedPane with the JTabbedPane.WRAP_TAB_LAYOUT and width of all of the tabs is higher than size of the window the tabs are wrapped. But it should be wrapped when width of all tabs + width of the added component is higher than the size. I have no idea how to do this. Any ideas?
    Please see the screenshot: [http://img150.imageshack.us/img150/5629/btn.png|http://img150.imageshack.us/img150/5629/btn.png]

    Just a quick idea:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.*;
    class TabbedPaneTest {
      public JComponent makeUI() {
        UIManager.put("TabbedPane.tabAreaInsets",
                      new InsetsUIResource(6, 2, 0, 60));
        JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        sp.setTopComponent(makeTabPanel(new JTabbedPane()));
        sp.setBottomComponent(makeTabPanel(new ClippedTitleTabbedPane()));
        sp.setPreferredSize(new Dimension(320, 240));
        return sp;
      private JPanel makeTabPanel(final JTabbedPane tab) {
        tab.addTab("asdfasd", new JLabel("456746"));
        tab.addTab("1234123", new JScrollPane(new JTree()));
        tab.addTab("6780969", new JLabel("zxcvzxc"));
        tab.setAlignmentX(1.0f);
        tab.setAlignmentY(0.0f);
        JButton b = new JButton(new AbstractAction("add") {
          @Override public void actionPerformed(ActionEvent e) {
            tab.addTab("test", new JScrollPane(new JTree()));
        b.setAlignmentX(1.0f);
        b.setAlignmentY(0.0f);
        JPanel p = new JPanel();
        p.setLayout(new OverlayLayout(p));
        p.add(b);
        p.add(tab);
        return p;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          @Override public void run() { createAndShowGUI(); }
      public static void createAndShowGUI() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new TabbedPaneTest().makeUI());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    class ClippedTitleTabbedPane extends JTabbedPane {
      //XXX Nimbus NPE
      Insets tabInsets = UIManager.getInsets("TabbedPane.tabInsets");
      Insets tabAreaInsets = UIManager.getInsets("TabbedPane.tabAreaInsets");
      public ClippedTitleTabbedPane() {
        super(JTabbedPane.TOP);
        setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        addComponentListener(new ComponentAdapter() {
          @Override public void componentResized(ComponentEvent e) {
            initTabWidth();
      @Override
      public void insertTab(String title, Icon icon, Component component,
                            String tip, int index) {
        super.insertTab(title, icon, component, tip==null?title:tip, index);
        JLabel label = new JLabel(title, JLabel.CENTER);
        Dimension dim = label.getPreferredSize();
        label.setPreferredSize(
            new Dimension(0, dim.height+tabInsets.top+tabInsets.bottom));
        setTabComponentAt(index, label);
        initTabWidth();
      private void initTabWidth() {
        Insets insets = getInsets();
        int areaWidth = getWidth() - tabAreaInsets.left - tabAreaInsets.right
                                   - insets.left        - insets.right;
        int tabCount = getTabCount();
        int tabWidth = 0;
        switch(getTabPlacement()) {
          case LEFT: case RIGHT:
          tabWidth = areaWidth/4;
          break;
          case BOTTOM: case TOP: default:
          tabWidth = areaWidth/tabCount;
        int gap = areaWidth - (tabWidth * tabCount);
        if(tabWidth>80) {
          tabWidth = 80;
          gap = 0;
        tabWidth = tabWidth - tabInsets.left - tabInsets.right - 3;
        for(int i=0;i<tabCount;i++) {
          JLabel l = (JLabel)getTabComponentAt(i);
          if(l==null) break;
          int h = l.getPreferredSize().height;
          l.setPreferredSize(new Dimension(tabWidth+((gap>0)?1:0), h));
          gap--;
        revalidate();
    }

  • Firefox has become other browsers on my windows computer, with their icon. I can't uninstall or redownload Firefox without error message

    Firefox has become internet explorer or google chrome, with their icon and everything on my windows XP computer. I cannot uninstall or redownload Firefox without it saying "Firefox must be closed to proceed with the uninstall/install. Please close Firefox to continue." It says that when I dont even have Firefox open, and I closed everything with task manager. How can I get Firefox back? It's the only brower I ever use.

    Please try a reboot of your pc and if that doesn't work, try the following:
    Certain Firefox problems can be solved by performing a ''Clean reinstall''. This means you remove Firefox program files and then reinstall Firefox. Please follow these steps:
    '''Note:''' You might want to print these steps or view them in another browser.
    #Download the latest Desktop version of Firefox from http://www.mozilla.org and save the setup file to your computer.
    #After the download finishes, close all Firefox windows (click Exit from the Firefox or File menu).
    #Delete the Firefox installation folder, which is located in one of these locations, by default:
    #*'''Windows:'''
    #**C:\Program Files\Mozilla Firefox
    #**C:\Program Files (x86)\Mozilla Firefox
    #*'''Mac:''' Delete Firefox from the Applications folder.
    #*'''Linux:''' If you installed Firefox with the distro-based package manager, you should use the same way to uninstall it - see [[Installing Firefox on Linux]]. If you downloaded and installed the binary package from the [http://www.mozilla.org/firefox#desktop Firefox download page], simply remove the folder ''firefox'' in your home directory.
    #Now, go ahead and reinstall Firefox:
    ##Double-click the downloaded installation file and go through the steps of the installation wizard.
    ##Once the wizard is finished, choose to directly open Firefox after clicking the Finish button.
    Please report back to see if this helped you!

Maybe you are looking for

  • Interested in subscribing to iTunes Match but concerned about number of devices

    My family and I all share 1 iTunes library. All purchases are made using the same AppleID account. We currently have 17 apple devices and will most likely be adding more with Xmas coming up next month. We are interested in subscribing to iTunes Match

  • Exchange rate issue for import po

    Dear friends, my client book a po in usd for the main party but the custom duty condation we are mataining in inr for a different ....now we have paid advance against the bill now the bill has come we need to clear the COMMISSIONER OF CUSTOMS account

  • Converting images that include text boxes and callouts in FM

    Hello, I'm on a new project (TCS 3.5, RH 9, FM 10) that requires me to include text boxes and lines (callouts) on top / in front of many of the images in FM. The reason they are not allowing me to add the text/callouts to the images themselves is bec

  • Acrobat x upgrade ripoff?

    The upgrade price to Acrobat X Pro is $199, from Acrobat X,9,8,7 Standard.  See http://www.adobe.com/products/acrobatpro/buying-guide.html The upgrade price to Acrobat X Pro ALSO is $199, from Acrobat Pro Extended.  I paid a lot of money for Acrobnat

  • I-touch 4g users! Can I pick your brains?

    Am thinking of getting the I-touch 4g, was going to hold off until the 5g came out but its so up in the air and it feels like too long to wait, plus I'm hearing mixed things about it and seems like it wont suit me a much as the 4g would. So, question