Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-06-2008, 02:35 PM
keffie91's Avatar
Member
 
Join Date: Jun 2008
Location: The Netherlands
Posts: 35
Rep Power: 0
keffie91 is on a distinguished road
Default set * at tab title
Hello I am building a Programming editor. It make us of a JTabbedPane. Now I wat that there appears a * at the tab when your file is not saved.

I wrote this:
private class MyKeyListener implements KeyListener{
public void keyPressed(KeyEvent e){
String title = tab.getTitleAt(tab.getSelectedIndex());
String update = title + "*";
tab.setTitleAt(tab.getSelectedIndex(),update);
}
}

This works not correct. Everytime I press a key, there is a * added to the tab title. You understand that I only want one *. I have tried something with a bool, but it was not a suc6.

Does anyone have any suggestions?
__________________
Never give up!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-06-2008, 04:07 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
String title = tab.getTitleAt(tab.getSelectedIndex());
String update = title + "*";
The problem is here.
What if title currently has an "*" at the end? This code will always add another "*".
You need to save the original title in a variable. Then either use the original or the original + "*" when you setTitle
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-06-2008, 04:24 PM
keffie91's Avatar
Member
 
Join Date: Jun 2008
Location: The Netherlands
Posts: 35
Rep Power: 0
keffie91 is on a distinguished road
Default
String original = tab.getTitleAt(tab.getSelectedIndex());
if(!(original.equals(original + "*"))){
tab.setTitleAt(tab.getSelectedIndex(),original + "*");
}
else{
tab.setTitleAt(tab.getSelectedIndex(),original);
}

I have also tried == instead of .equals . But i doesn't work.
__________________
Never give up!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-06-2008, 06:17 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Where is the title originally(the first time) set for tab?
That is what I mean by the original value.

tab.getTitleAt(tab.getSelectedIndex());
gets the current value, not the original value.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-06-2008, 06:21 PM
keffie91's Avatar
Member
 
Join Date: Jun 2008
Location: The Netherlands
Posts: 35
Rep Power: 0
keffie91 is on a distinguished road
Default
that is Untitled always. Because you begin always with a tab that has no name and is not saved. So if I write out the orginal text thus Untitled. Than you don't see the name of the document if you have saved it. End that is not what I want.
__________________
Never give up!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-06-2008, 06:25 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
What is returned the first time you do a getTitleAt()?
Is it an empty string? Or what?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 10-06-2008, 07:02 PM
keffie91's Avatar
Member
 
Join Date: Jun 2008
Location: The Netherlands
Posts: 35
Rep Power: 0
keffie91 is on a distinguished road
Default
The name of the saved file without the * character
__________________
Never give up!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 10-06-2008, 07:21 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
And how does that string get to be the title? How is it set? Via the add or via a setTitle? Whenever or whereever you FIRST set the title save that string as the original value of the title.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify HTML title tag Java Tip SWT 0 07-07-2008 04:44 PM
String Title case bugger New To Java 4 01-28-2008 05:06 PM
Hiding the frame’s title bar Java Tip Java Tips 0 12-21-2007 08:41 AM
How to alter the title of JOptionPane mew New To Java 2 12-17-2007 10:39 AM
How can I add an ICON on a JDialog's Title-Bar? iimasd AWT / Swing 2 11-06-2007 12:54 PM


All times are GMT +2. The time now is 05:38 PM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org