| Author |
blinking tab pane
|
sk said
Greenhorn
Joined: Mar 30, 2011
Posts: 5
|
|
i created a tabbed pane with 3 jPanel.
1 of them is for output display.
how can i make it's title blinking when there is output to be displayed?
|
 |
Tarun Bolla
Ranch Hand
Joined: Jun 20, 2011
Posts: 85
|
|
You can write a thread for setting the title of the Output tab (say tab #3 in (0, 1, 2, 3)) TABBEDPANE.setTitleAt(3, "Output") and TABBEDPANE.setTitleAt(3, " ") alternately with a 600 ms delay(sleep interval)...
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4166
|
|
Tarun Bolla wrote:You can write a thread for setting the title of the Output tab (say tab #3 in (0, 1, 2, 3)) TABBEDPANE.setTitleAt(3, "Output") and TABBEDPANE.setTitleAt(3, " ") alternately with a 600 ms delay(sleep interval)...
Did you try that to see what happens?
Also, I recommend you go through these two tutorials: How to Use Swing Timers and Concurrency in Swing.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4166
|
|
sk said wrote:i created a tabbed pane with 3 jPanel.
1 of them is for output display.
how can i make it's title blinking when there is output to be displayed?
You can try using setForegroundAt(...) using a Swing Timer.
|
 |
Tarun Bolla
Ranch Hand
Joined: Jun 20, 2011
Posts: 85
|
|
Darryl Burke wrote:
Did you try that to see what happens?
Here is a sample code that demonstrates what i mean...
After running it...click on the JLabel with Text "1" in the first tab and see that the output tab text blinks...
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
I personally would never use blinking. I'd instead use colouring - make it red or something like that when there's output, then make it black again when the tab is selected. Since Java 6 JTabbedPane has method setTabComponentAt which allows you to set a simple JLabel for that one tab, letting the default UI work for the others. There's no need for a timer then; keep a reference to this JLabel and simply change its foreground colour when needed.
Edit: or use setForegroundAt. I never knew this method existed. Thanks Darryl!
And Tarun, you clearly have not read the concurrency in Swing page Darryl linked to, or you wouldn't be using a regular thread.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4166
|
|
Tarun Bolla wrote:
Darryl Burke wrote:
Did you try that to see what happens?
Here is a sample code that demonstrates what i mean...
1. That's not what you wrote earlier.
TABBEDPANE.setTitleAt(3, "Output") and TABBEDPANE.setTitleAt(3, " ")
2. The number of spaces is totally dependent on the Font, making this a very fragile 'solution'.
Here's a more robust approach:
|
 |
Tarun Bolla
Ranch Hand
Joined: Jun 20, 2011
Posts: 85
|
|
If not spaces ... colors can do that....
|
 |
 |
|
|
subject: blinking tab pane
|
|
|