Flashing a tab in JideTabbedPane

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

Flashing a tab in JideTabbedPane

Postby karthickdv » Wed Apr 30, 2008 11:07 pm

Hi,

I have a JideTabbedPane. I want to flash a particular tab(say 2nd tab) for 5 seconds. How do I do that? Can you please reply ASAP.
karthickdv
 
Posts: 5
Joined: Sat Apr 26, 2008 4:04 am

Postby JIDE Support » Wed Apr 30, 2008 11:15 pm

I did something like this in my spare time but didn't make it part of JIDE release. I attached the source code. Feel free to use.


TabbedPaneFlashable class which is based on Flashable in JIDE
Code: Select all
/*
 * @(#)TabbedPaneFlashable.java 3/16/2007
 *
 * Copyright 2002 - 2007 JIDE Software Inc. All rights reserved.
 */

package com.jidesoft.swing;

import javax.swing.*;
import java.awt.*;

public class TabbedPaneFlashable extends Flashable {
    private int _tabIndex;
    private Color _background;
    private Color _foreground;
    private Color _savedBackground;
    private Color _savedForeground;

    public TabbedPaneFlashable(JTabbedPane component) {
        super(component);
    }

    public TabbedPaneFlashable(JTabbedPane component, int tabIndex, Color background, Color foreground) {
        super(component);
        _tabIndex = tabIndex;
        _background = background;
        _foreground = foreground;
        if (getComponent() instanceof JTabbedPane) {
            JTabbedPane tabbedPane = (JTabbedPane) getComponent();
            _savedBackground = tabbedPane.getBackgroundAt(_tabIndex);
            _savedForeground = tabbedPane.getForegroundAt(_tabIndex);
        }
    }

    public void flash() {
        boolean flashOn = getSynchronizedFlashFlag();
        if (getComponent() instanceof JTabbedPane) {
            JTabbedPane tabbedPane = (JTabbedPane) getComponent();
            if (flashOn) {
                if (_foreground != null) {
                    tabbedPane.setForegroundAt(_tabIndex, _foreground);
                }
                if (_background != null) {
                    tabbedPane.setBackgroundAt(_tabIndex, _background);
                }
            }
            else {
                if (_savedForeground != null) {
                    tabbedPane.setForegroundAt(_tabIndex, _savedForeground);
                }
                if (_savedBackground != null) {
                    tabbedPane.setBackgroundAt(_tabIndex, _savedBackground);
                }
            }
            if (tabbedPane instanceof JideTabbedPane) {
                ((JideTabbedPane) tabbedPane).repaintTabAreaAndContentBorder();
            }
        }
    }

    public void clearFlashing() {
        if (getComponent() instanceof JTabbedPane) {
            JTabbedPane tabbedPane = (JTabbedPane) getComponent();
            tabbedPane.setForegroundAt(_tabIndex, _savedForeground);
            tabbedPane.setBackgroundAt(_tabIndex, _savedBackground);
        }
    }
}



A demo class. You need to put it into JIDE examples project (in either eval package or formal release) in order to compile.

Code: Select all
/*
 * @(#)TabbedPaneFlashableDemo.java 3/16/2007
 *
 * Copyright 2002 - 2007 JIDE Software Inc. All rights reserved.
 */

import com.jidesoft.dialog.ButtonPanel;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.Flashable;
import com.jidesoft.swing.JideTabbedPane;
import com.jidesoft.swing.TabbedPaneFlashable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * Demoed Component: {@link com.jidesoft.grid.HierarchicalTable} <br> Required jar files:
 * jide-common.jar, jide-grids.jar <br> Required L&F: Jide L&F extension required
 */
public class TabbedPaneFlashableDemo extends AbstractDemo {
    protected static final Color BG1 = new Color(255, 255, 255);

    private JTabbedPane _tabbedPane;

    public TabbedPaneFlashableDemo() {
    }

    public String getName() {
        return "TabbedPane Demo (Flashing)";
    }

    public String getProduct() {
        return PRODUCT_NAME_COMMON;
    }

    public Component getDemoPanel() {
        _tabbedPane = createTabbedPane();
        return _tabbedPane;
    }

    @Override
    public String getDescription() {
        return "";
    }

    @Override
    public String getDemoFolder() {
        return "G17. StyleTable";
    }

    public static void main(String[] args) {
        LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
        showAsFrame(new TabbedPaneFlashableDemo());
    }

    @Override
    public Component getOptionsPanel() {
        ButtonPanel buttonPanel = new ButtonPanel(SwingConstants.TOP);
        buttonPanel.addButton(new JButton(new AbstractAction("Start Flashing") {
            public void actionPerformed(ActionEvent e) {
                Flashable flashable;
                if (!Flashable.isFlashableInstalled(_tabbedPane)) {
                    flashable = new TabbedPaneFlashable(_tabbedPane, 1, Color.RED, Color.WHITE);
                }
                else {
                    flashable = Flashable.getFlashable(_tabbedPane);
                }

                if (flashable.isFlashing()) {
                    flashable.stopFlashing();
                    putValue(Action.NAME, "Start Flashing");
                }
                else {
                    flashable.startFlashing();
                    putValue(Action.NAME, "Stop Flashing");
                }
            }
        }));
        return buttonPanel;
    }

    private JTabbedPane createTabbedPane() {
        JTabbedPane tabbedPane = new JideTabbedPane();
        tabbedPane.addTab("Mail", createPanel());
        tabbedPane.addTab("Calendar", createPanel());
        tabbedPane.addTab("Contacts", createPanel());
        tabbedPane.addTab("Tasks", createPanel());
        tabbedPane.addTab("Notes", createPanel());
        tabbedPane.addTab("Folders", createPanel());
        tabbedPane.addTab("Shortcuts", createPanel());
        tabbedPane.setPreferredSize(new Dimension(500, 200));
        return tabbedPane;
    }

    private JScrollPane createPanel() {
        return new JScrollPane(new JTextArea());
    }
}
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby karthickdv » Wed Apr 30, 2008 11:17 pm

Thanks for such a quick response. I will try it!!
karthickdv
 
Posts: 5
Joined: Sat Apr 26, 2008 4:04 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 15 guests