Change JDialog Title by JTextField

Hi there!
I got the following problem:
I have a JDialog with a given title "New Task: "
When I enter text into a JTextField, the content of the textfield should be appended to the title... e.g.
1) New Task:
2) New Task: Meeting
3) New Task: Meetin
and so on... difficult to explain...

I really can't see where you're stuck.import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JDialog;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
public class DialogSetTitle extends JDialog {
   String title;
   public DialogSetTitle(String title) {
      super(new Frame(), title);
      this.title = title;
   void makeUI() {
      JTextField textField = new JTextField(20);
      textField.getDocument().
              addDocumentListener(new DocumentListener() {
         @Override
         public void insertUpdate(DocumentEvent e) {
            setTitle(e);
         @Override
         public void removeUpdate(DocumentEvent e) {
            setTitle(e);
         @Override
         public void changedUpdate(DocumentEvent e) {
            setTitle(e);
         private void setTitle(DocumentEvent e) {
            Document document = e.getDocument();
            try {
               String suffix = document.getText(0, document.getLength());
               DialogSetTitle.this.setTitle(title + suffix);
            } catch (BadLocationException ex) {
               ex.printStackTrace();
      setSize(300, 80);
      setLocationRelativeTo(null);
      setLayout(new FlowLayout());
      add(textField);
      addWindowListener(new WindowAdapter() {
         @Override
         public void windowClosing(WindowEvent e) {
            System.exit(0);
      setVisible(true);
   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
            new DialogSetTitle("New Task: ").makeUI();
}db

Similar Messages

  • Keeping a JDialog Title Centered.

    Guys:
    I have a strange problem and am not sure how to get around it. I am ising setTitle() to place a title string on my JDialog. Now I toulf like to center the title. On my desk PC I do this by simply inserting enough spaces before the title to center it. When I run there the title is beautifully centered. However, when I take my code to another computer (especially one made by another manufacturer) it is totally not centered. Is there a way to insure my title stays centered no matter what machine my code is running on? SetTitle(String) takes only a String argument.
    Thank you in advance.
    Phil Rossomando

    lol, I'm talking about the WIndows OS, not java.awt.Window.
    Give this a spin, but only on a Windows machine.import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class DialogCenterTitle {
       JDialog dialog;
       JTextField textField;
       final Toolkit kit = Toolkit.getDefaultToolkit();
       final Font font = (Font) kit.getDesktopProperty("win.frame.captionFont");
       // titleHeight is a proxy for the width of the
       // square space reserved for the titlebar icon.
       final int titleHeight = (Integer) kit.getDesktopProperty(
               "win.frame.captionHeight");
       void makeUI() {
          textField = new JTextField(50);
          textField.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
                dialog.setTitle(getCenteredTitle(textField.getText()));
          JPanel panel = new JPanel();
          panel.addComponentListener(new ComponentAdapter() {
             @Override
             public void componentResized(ComponentEvent e) {
                dialog.setTitle(getCenteredTitle(dialog.getTitle().trim()));
          panel.add(textField);
          panel.revalidate();
          dialog = new JDialog();
          dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          dialog.add(panel);
          dialog.pack();
          String title = "Type in the text field and press <Enter> to change this title.";
          title = getCenteredTitle(title);
          dialog.setTitle(title);
          dialog.setLocationRelativeTo(null);
          dialog.setVisible(true);
       private String getCenteredTitle(String title) {
          Graphics graphics = dialog.getGraphics();
          FontMetrics metrics = graphics.getFontMetrics(font);
          int spaceWidth = (dialog.getWidth() - metrics.stringWidth(title)) / 2
                  - dialog.getInsets().left - titleHeight;
          String spaces = "";
          while (metrics.stringWidth(spaces) < spaceWidth) {
             spaces += " ";
          return spaces + title;
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new DialogCenterTitle().makeUI();
    }db

  • Chinese characters in JDialog title?

    Hi all,
    I'm running the JDK on an english language machine, but starting a program with the command line prompt -Duser.language=zh to display Chinese characters.
    If I have some chinese characters in a JDialog title, or a JOptionPane message or title, the characters are replaced with boxes. I can see Chinese characters everywhere else, in JLabels, text boxes, JTrees, etc, so its not a problem with fonts.
    Has anybody else had this problem? Is there a work around for this? Is it something to do with the UIManager setting the fonts for JOptionPane's?
    thanks,
    Justin

    Try calling these at the start of your app before showing any windows:
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    If that doesn't work, I don't know what would. The default is that the OS draws the frame titlebar, and on English systems, it's not going to display chars that aren't in the charset. I'm sure you could change that by installing other charsets, but you can't really do that on other people's machines.

  • How to Change Default Title and Icon of Forms 5.0 Runtime

    Whenever i run Forms 5.0 runtime , it always shows
    'Developer 2000 Forms Runtime for Windows 95/ NT'.
    If i set a title to the main window then also the above message preceeds my Title of Window.
    Is there any way to remove that ????
    My Application is ready for delivery but the only problem is this title message. and also,, I want to change my own ICON in place of deafult icon
    How to do that

    Hi,
    You can always change you Window title at runtime.
    On Windows, You ALWAYS have a container window (There is an option from 5.0 onwards to avoid this container window) and at least one window in you applciation e.g. window0.
    Use the following command to change the title of the MDI window:
    set_window_property (FORMS_MDI_WINDOW,title,'My Application');
    For window0, try this:
    set_window_property ('WINDOW0',title,'Registration of Employee');
    Please see all the options available in the online help of forms under SET_WINDOW_PROPERTY.
    Bye,
    Vani
    null

  • How do I change the title FAQ to Knowledgebase?

    We've widened the use of the FAQ (module) to be a knowledgebase.  But, we have not been able to change the title on the detail page from FAQ.
    Is there a way to change the title?

    Batch renaming is not yet implemented in Photos. As a work-around for now you can search for Automator scripts that will do it.
    Sort order of Album list, Album contents and Folder contents can be changed by checking or unchecking the Keep Sorted By... option under the View menu. I know, very limited options...
    You can request features, point out bugs, etc, at Apple Feedback pages: 
      http://www.apple.com/feedback/
    Or directly for Photos:
    https://www.apple.com/feedback/photos.html

  • Is there any way to change a title for streaming video in QT Pro?

    I'm trying to follow several streaming feeds at the same time, all with unhelpful titles.
    For example, this is the URL I'm using to view the ROV 2 feed for Discoverer Enterprise.
    http://mfile.akamai.com/97892/live/reflector:21145.asx?bkup=21327
    which results in the title, reflector:21145.asx?bkup=21327.

    Actually, what I was wanting to know is if I could just change the title while watching the streaming video rather than saving the feed. I can do this in a VLC playlist but I can't seem to figure out how to open multiple windows for feeds in VLC. Also, VLC doesn't let me go back in the cached feed to see and/or save snippets which I can easily do in QuickTime Pro.
    I have been able to save the streaming feeds like this although I have the $30 upgrade for Flip4Mac which I needed to export for YouTube. There may be a way to do the same thing with something free but I know less than nothing about video and this worked.
    Move the playhead slider to start of snippet
    Type "i" to get slider for start of snippet
    Move the playhead slider to end of snippet
    Type "o" to get slider for end of snippet
    Adjust the "i" and "o" sliders if needed.
    Right click on the feed and choose copy.
    Go to File -> New Player (command N)
    Go to Edit -> Paste (command V)
    Go to File -> Save (command S) and save as self-contained movie
    After that I use the file I just saved with the directions on YouTube to export it to a file that will process on their site.
    Here is an example that shows a ROV being lowered from the deck of its mothership into the water.
    http://www.youtube.com/watch?v=VsYinE5cNx8
    I saved it from this streaming feed which I loaded into QuickTime Pro (File -> Open URL or command U and paste URL). I seem to recall I needed the free Flip4Mac to view this in QuickTime.
    http://mfile.akamai.com/97892/live/reflector:47175.asx?bkup=21144
    I'm all set with what I want to do other than being able to change the titles on the feeds as I'm watching them in QuickTime Pro.

  • How can i change the title and image of  published exe

    Hi ,
    I have published a fla file in exe format .
    how can i change the title and image of this exe? do I ve to
    use some of the available softwares in the market? cant i do the
    customised setting in the flash player itself?

    On Fri, 4 Apr 2008 06:21:15 +0000 (UTC), "mFlexDev"
    <[email protected]> wrote:
    > I have published a fla file in exe format .
    > how can i change the title and image of this exe?
    I beleave the easiest way is to use PEResourceExplorer,
    Resource
    Hacker or similar software to modify EXE resources, such as
    window
    title and window icon.

  • How to change the title of a block/form/table in the WebIC CRM 2007 ?

    Hi,
    We want to change the title of a block in the work area for example from 'Account details' to 'Partner details'.
    After investigation we think that we have to change the text in SOTR_EDIT transaction by editing the Alias or defining a new one with the desired title.
    The problem is that when we search for the alias in the OTR maintain initial screen , we get a list and we don't know which one is the alias associated to the title of our view..
    Is it the right way to proceed or is there any other solution ?
    Your help is highly appreciated.
    Regards
    Nabil.

    Hi Nabil,
    Its so simple,
    Go to the Component/ View : BP_HEAD/BPHEADOverview
    Click on the CONFIGURATION tab.
    Alt+Click on the BP_HEAD : AccountViewSet : Account Details
    Juss Change the Title Account Details to Partner Details.
    That's it. Your block title is changed now from Account Details to Partner Details.
    Best Regards,
    Shiven

  • How to change the title of an existing document?

    I have looked in online manuals and there are no headings for this.  I wish to change the title of an existing documents but can find no way to do so.  Any one have help on this? 

    You can also change the file name in Finder.
    peter

  • How to change the title of an object in the build order window?

    In Keynote '09 v5.1.1 (1034)... How to change the title of an object in the build order window from the default "dropped image" to a specific title?
    I'm running the following:
      Model Name: MacBook Pro
      Model Identifier: MacBookPro2,1
      Processor Name: Intel Core 2 Duo
      Processor Speed: 2.33 GHz
      Number Of Processors: 1
      Total Number Of Cores: 2
      L2 Cache: 4 MB
      Memory: 2 GB
      Bus Speed: 667 MHz
      Boot ROM Version: MBP21.00A5.B08
      SMC Version (system): 1.14f5

    Custom names can't be applied to objects in the build list.
    They are labeled as either; text, shape, table, chart or the filename of an image

  • Does anybody know how to change the title of your podcast on iTunes and the description of it?

    I was working on my feed site and when the podcast popped up on iTunes I realized that I put the wrong info and title on it. Anybody know?

    You change the title and descriptions by entering the changed versions in wherever you originally entered the items in whatever system you are using to create your feed, then re-publish the feed; it will take the iTunes Store a couple of days or so to catch up.
    However, if the method you are using to create your feed is one of those which uses the title of the podcast as part of the URL, and this changes if you change the title, then if you change the URL as a result the iTunes Store will lose contact with it and fail to update in future: so be careful about this.

  • Change browser title from framename

    Hello, I've created with robohelp 8 a WebHelp. The browser display's in the title bar the title of my project. Is it possible to change this title when you choose a topic? Like you click from the startpage (title=startpage) on topic A, the the browser title changes to A? I've searched the web for answers, but the ones I found wouldn't work in my Webhelp. For example there is a javascript, which you include in your topic HTML:
    <body OnLoad="parent.document.title=document.title"> Unfortunately this doesn't work.
    Does anybody know how to solve this?

    I have found the solution:
    Just put this code in your topic pages:
    <body onload="parent.parent.document.title=document.title">
    This works great. The only problem is that when you put this code in your masterpage's RoboHelp strips the code, so in you export such as webhelp the code has disappeared. The solution is to modify the page's afther exporting your webhelp. I use dreamweaver, this tool has an batch function for search and replace which makes it an easy job!
    I wil send Adobe a suggestion to make this function in the software, that would be easier.

  • How do you change the title of a validation alert?

    Hello I have some <CFINPUT> code with validation
    onSubmit that is working well. The problem is my boss wants me to
    change the title text on the alert. The alert is generated by the
    <cfinput> validation and not actually in the code I write.
    How would I go about changing the title? To be clear this would be
    the title usually in blue in the alert window that has the X to
    close the window on the right hand side.
    Here is a sample of my code that is using the validation...
    Thanks in advance for your help!
    Dave

    quote:
    Originally posted by:
    north.dave
    I am using <cfform> is that the same as using an HTML
    form?
    If the format attribute is "HTML" or omitted, then yes. The
    error messages created via cfinput are displayed in a Javascript
    alert dialog. The alert dialog can display a user defined message
    but the title cannot be changed.
    This is an older reference (but still accurate)
    http://docs.sun.com/source/816-6408-10/window.htm#1201497

  • How to change the text in JTextField Dynamically

    i am trying to change the contents of JTextField dynamically like this
    textfield.setText();but it is giving error...........how can i do it....

    here is the code .....it is showing error in line 18 and 20 as identifier expected
    their i am trying to make JTextField editable....
    plz have a look
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    import javax.swing.SwingUtilities.*;
    import javax.swing.filechooser.FileFilter;
    //import javax.swing.JEditorPane;
    import java.net.URL;
    public class tm extends JFrame implements ActionListener
    public JTextField[] programtext = new JTextField[30];
    public JTextField[] tapetext = new JTextField[30];
    tapetext.setEditable(true);
    public JTextField[] statetext = new JTextField[30];
    statetext.setEditable(true);
    int count =0;
    public static void main (String arg[]){
    tm m=new tm();
    m.setSize(1000,500);
    m.show();
    JButton loadp, run, step,loadi,loads;
    public tm()
    Container c ;
    c = getContentPane();
    c.setLayout(new FlowLayout());
    loadi = new JButton("LOAD INPUT STRING");
    c.add(loadi);
    loadi.addActionListener(this);
    loadi.setBounds(200,25,100,50);
    loadp = new JButton("LOAD PROGRAM");
    c.add(loadp);
    loadp.addActionListener(this);
    loadp.setBounds(300,25,100,50);
    run = new JButton("RUN");
    c.add(run);
    run.addActionListener (this);
    run.setBounds(400,25,100,50);
    step = new JButton("STEP");
    c.add(step);
    step.addActionListener(this);
    step.setBounds(500,25,100,50);
    loads = new JButton("LOAD STATES");
    c.add(loads);
    loads.addActionListener(this);
    loads.setBounds(600,25,100,50);
    JPanel prog = new JPanel();
    prog.setLayout(new GridLayout(30,1));
    for(int i=0;i<programtext.length;i++)
    programtext= new JTextField(10);
    prog.add(programtext[i]);
    JPanel tape = new JPanel();
    tape.setLayout(new GridLayout(30,1));
    for(int i=0;i<tapetext.length;i++)
    tapetext[i]= new JTextField(10);
    tape.add(tapetext[i]);
    JPanel state = new JPanel();
    state.setLayout(new GridLayout(30,1));
    for(int i=0;i<statetext.length;i++)
    statetext[i]= new JTextField(10);
    state.add(statetext[i]);
    JPanel contentPane3 = new JPanel();
    contentPane3.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
    contentPane3.setLayout(new BorderLayout());
    contentPane3.add(state, BorderLayout.CENTER);
    contentPane3.add(c, BorderLayout.NORTH);
    contentPane3.add(prog, BorderLayout.WEST);
    contentPane3.add(tape, BorderLayout.EAST);
    setContentPane(contentPane3);
    public void actionPerformed(ActionEvent e)
    try{
    if(e.getSource ()==loadp)
    JFileChooser chooser=new JFileChooser();
    int r= chooser.showOpenDialog(this);
    if(r==JFileChooser.APPROVE_OPTION )
    String name=chooser.getSelectedFile().getName();
    File f=chooser.getSelectedFile();
    FileInputStream filestream = new FileInputStream(f);
    BufferedInputStream bufferstream = new BufferedInputStream(filestream);
    DataInputStream datastream = new DataInputStream(bufferstream);
    String record = null;
    programtext[0].setText("");
    try { 
    int i = 0;
    while (true)
    record=datastream.readLine();
    if(record == null){
    break;
    programtext[i].setText(record);
    i++;
    count = count + 1;
    System.out.println ("the no of lines of the program are"+ count);
    catch (Exception p)
    System.out.println(p);
    else if(e.getSource()==loads)
    JFileChooser chooser3=new JFileChooser();
    int r3= chooser3.showOpenDialog(this);
    if(r3==JFileChooser.APPROVE_OPTION)
    String name=chooser3.getSelectedFile ().getName();
    File f3=chooser3.getSelectedFile();
    FileInputStream filestream3 = new FileInputStream(f3);
    BufferedInputStream bufferstream3 = new BufferedInputStream(filestream3);
    DataInputStream datastream3 = new DataInputStream(bufferstream3);
    String record3 = null;
    statetext[0].setText("");
    try { 
    int i = 0;
    while (true)
    record3=datastream3.readLine();
    if(record3 == null){
    break;
    statetext[i].setText(record3);
    i++;
    catch (Exception p3)
    System.out.println(p3);
    else if(e.getSource()==loadi)
    JFileChooser chooser2=new JFileChooser();
    int r2= chooser2.showOpenDialog(this);
    if(r2==JFileChooser.APPROVE_OPTION )
    String name=chooser2.getSelectedFile().getName();
    File f2=chooser2.getSelectedFile();
    FileInputStream filestream2 = new FileInputStream(f2);
    BufferedInputStream bufferstream2 = new BufferedInputStream(filestream2);
    DataInputStream datastream2 = new DataInputStream(bufferstream2);
    String record2 = null;
    tapetext[0].setText("");
    try { 
    int i = 0;
    while (true)
    record2=datastream2.readLine();
    if(record2 == null){
    break;
    tapetext[i].setText(record2);
    i++;
    catch (Exception p2)
    System.out.println(p2);
    else if(e.getSource ()==run)
    String temp="";
    String statetemp=" ";
    String tapetemp=" ";
    int l=0;
    int tp=0;
    String pars[][] = new String[50][5];
         for(int m=0;m<count;m++){
    temp = programtext[m].getText();
    String str[]=temp.split(" ");
    for(int k=0;k<5;k++){
    pars[m][k] =str[k];
    System.out.println(pars[m][k]);
    statetemp = statetext[0].getText();
    tapetemp = tapetext[l].getText();
    while(pars[tp][0]==statetemp && pars[tp][1]==tapetemp && tp><count)
         statetemp = pars[tp][2];
         tapetemp = pars[tp][3];
         statetext[0].setText() = statetemp;
         tapetext[tp].setText() = tapetemp;
         if(pars[tp][4]=="R")
         l=l+1;
         else{
         l=l-1;
         tp++;      
    else if(e.getSource()==step)
    catch(Exception t)
    System.out.println(t);

  • FPM - How to change the title in a component configuration

    Hello,
    I am working with the component configuration EHHSS_INC_REC_NRM_QAF_V3 (version 7.31) and I need to change the title of the tab. I created an OTR with the text "Report Near Miss test". I changed the application title and I also change the tooltip text in the IDR to this OTR.
    When I executed it, I only see the modication on the tooltip. Why the application title is not shown with the modification? How can I modify also the tab and the title?
    Thank you for your help!
    Marie-Josée

    Hello,
    Thank you for your time. The application configuration is link to the business object EHHSS_INCIDENT...I did not find a view. I do not have a lot of experience in FPM so can you show me how? I looked in BOPF but I am not able to do it with an enhancement
    Marie-Josée

Maybe you are looking for

  • How to display Doc file format in the JEditPane?

    At this time , JEditPane supports RTF and HTML file format ,but Could anyone tell me how to display DOC file format using JEditPane or other JTextComponents? Thx a lot! Caton

  • Apex_collection.add_member not adding all fields

    I am trying to add the contents of three page items into a collection, and to verify, I queried the collection for the three fields and output them to other page items. The problem is, only one field returns a value. Background: I set up the collecti

  • AP Accrual write off

    Hi, Kindly help to me to understand under what situation we need to write-off the AP accrual ? Wouldn't we want to accrue all univoiced Receipts ? Thanks

  • I have AVG 2011 Free and Firefox will not connect to update server

    Firefox 4 tries to update but cannot connect to the update server. I have AVG 2011 Free Version which is not covered in your help page. It does not have the facilities that your suggestions for earlier versions of AVG does (ie anywhere that shows fir

  • Solution for Poor Apple TV Exports?

    So I've been doing many export tests from FCP X.  My main goal being for Apple TV 2 playback.  I even used thed the Current choice from the basic Export Media option.  I expected that to look like the original.  I hardly looked better than the Apple