Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-06-2008, 04:35 PM
keffie91's Avatar
Member
 
Join Date: Jun 2008
Location: The Netherlands
Posts: 26
keffie91 is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 10-06-2008, 06:07 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
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, 06:24 PM
keffie91's Avatar
Member
 
Join Date: Jun 2008
Location: The Netherlands
Posts: 26
keffie91 is on a distinguished road
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, 08:17 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
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, 08:21 PM
keffie91's Avatar
Member
 
Join Date: Jun 2008
Location: The Netherlands
Posts: 26
keffie91 is on a distinguished road
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, 08:25 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
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, 09:02 PM
keffie91's Avatar
Member
 
Join Date: Jun 2008
Location: The Netherlands
Posts: 26
keffie91 is on a distinguished road
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, 09:21 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
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
Sponsored Links
Reply


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

vB 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 06:44 PM
String Title case bugger New To Java 4 01-28-2008 07:06 PM
Hiding the frame’s title bar Java Tip Java Tips 0 12-21-2007 10:41 AM
How to alter the title of JOptionPane mew New To Java 2 12-17-2007 12:39 PM
How can I add an ICON on a JDialog's Title-Bar? iimasd AWT / Swing 2 11-06-2007 02:54 PM


All times are GMT +3. The time now is 04:34 PM.


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