Results 1 to 8 of 8
  1. #1
    keffie91's Avatar
    keffie91 is offline Member
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    35
    Blog Entries
    1
    Rep Power
    0

    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! ;)

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,335
    Rep Power
    25

    Default

    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

  3. #3
    keffie91's Avatar
    keffie91 is offline Member
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    35
    Blog Entries
    1
    Rep Power
    0

    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! ;)

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,335
    Rep Power
    25

    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.

  5. #5
    keffie91's Avatar
    keffie91 is offline Member
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    35
    Blog Entries
    1
    Rep Power
    0

    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! ;)

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,335
    Rep Power
    25

    Default

    What is returned the first time you do a getTitleAt()?
    Is it an empty string? Or what?

  7. #7
    keffie91's Avatar
    keffie91 is offline Member
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    35
    Blog Entries
    1
    Rep Power
    0

    Default

    The name of the saved file without the * character
    Never give up! ;)

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,335
    Rep Power
    25

    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.

Similar Threads

  1. String Title case
    By bugger in forum New To Java
    Replies: 6
    Last Post: 01-31-2012, 01:21 PM
  2. How to modify HTML title tag
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-07-2008, 04:44 PM
  3. Hiding the frameís title bar
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-21-2007, 08:41 AM
  4. How to alter the title of JOptionPane
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-17-2007, 10:39 AM
  5. How can I add an ICON on a JDialog's Title-Bar?
    By iimasd in forum AWT / Swing
    Replies: 2
    Last Post: 11-06-2007, 12:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •