Results 1 to 8 of 8
Thread: set * at tab title
- 10-06-2008, 02:35 PM #1
- Join Date
- Jun 2008
- Location
- The Netherlands
- Posts
- 35
- Blog Entries
- 1
- Rep Power
- 0
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! ;)
- 10-06-2008, 04:07 PM #2
The problem is here.String title = tab.getTitleAt(tab.getSelectedIndex());
String update = title + "*";
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
- 10-06-2008, 04:24 PM #3
- Join Date
- Jun 2008
- Location
- The Netherlands
- Posts
- 35
- Blog Entries
- 1
- Rep Power
- 0
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! ;)
- 10-06-2008, 06:17 PM #4
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.
- 10-06-2008, 06:21 PM #5
- Join Date
- Jun 2008
- Location
- The Netherlands
- Posts
- 35
- Blog Entries
- 1
- Rep Power
- 0
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! ;)
- 10-06-2008, 06:25 PM #6
What is returned the first time you do a getTitleAt()?
Is it an empty string? Or what?
- 10-06-2008, 07:02 PM #7
- Join Date
- Jun 2008
- Location
- The Netherlands
- Posts
- 35
- Blog Entries
- 1
- Rep Power
- 0
The name of the saved file without the * character
Never give up! ;)
- 10-06-2008, 07:21 PM #8
Similar Threads
-
String Title case
By bugger in forum New To JavaReplies: 6Last Post: 01-31-2012, 01:21 PM -
How to modify HTML title tag
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:44 PM -
Hiding the frame’s title bar
By Java Tip in forum Java TipReplies: 0Last Post: 12-21-2007, 08:41 AM -
How to alter the title of JOptionPane
By mew in forum New To JavaReplies: 2Last Post: 12-17-2007, 10:39 AM -
How can I add an ICON on a JDialog's Title-Bar?
By iimasd in forum AWT / SwingReplies: 2Last Post: 11-06-2007, 12:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks