Thread Subject: Using MLDesktop to change window title during startup

Subject: Using MLDesktop to change window title during startup

From: Albert

Date: 30 Sep, 2009 18:43:05

Message: 1 of 4

I use com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.setTitle() in my startup.m. In R2009b this value is reset to the Mathworks default after startup.m runs. I do not see anything in matlabrc.m that could reset this so i believe something after matlabrc is making this change. My change stays momentarily and is stays if startup is run from the command line.
Any thoughts on how to make this stay from inside of startup?

I use this to display my environment path after the version name. Like this:
import com.mathworks.mde.desk.MLDesktop;
MLDesktop.getInstance.getMainFrame.setTitle([char(MLDesktop.getInstance.getMainFrame.getTitle), ' my envir path'])

Subject: Using MLDesktop to change window title during startup

From: Jan Simon

Date: 30 Sep, 2009 19:44:03

Message: 2 of 4

Dear Albert!

> I use com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.setTitle() in my startup.m. In R2009b this value is reset to the Mathworks default after startup.m runs. I do not see anything in matlabrc.m that could reset this so i believe something after matlabrc is making this change. My change stays momentarily and is stays if startup is run from the command line.
> Any thoughts on how to make this stay from inside of startup?

Create a TIMER to set the window title 1 second after startup.m has finished.

Good luck, Jan

Subject: Using MLDesktop to change window title during startup

From: Albert

Date: 5 Oct, 2009 20:32:04

Message: 3 of 4

> Create a TIMER to set the window title 1 second after startup.m has finished.
>
Thanks.
I found that 1 second was to short. Four worked fine, so i used 5 seconds for a safty margin. Here is the code I used at the bottom of my startup function:

% check for previously created startup_timer
T_existing = timerfindall('Name','startup_timer');
if ~isempty(T_existing)
    stop(T_existing);
    delete(T_existing);
end
clear T_existing;
% create timer to change the window title
windowtitle = ['MATLAB ',version,', MyEnvir ',My_version];
com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.setTitle(windowtitle);
T = timer('UserData',windowtitle);
set(T,'Name','startup_timer'); % name so we can find it later
set(T,'TimerFcn',@setMainFrameTitle); % set timer function
set(T,'BusyMode','queue');
set(T,'StartDelay',5); % run 5 seconds after start
set(T,'ObjectVisibility','off'); % hide from timerfind
start(T); % start the timer

function setMainFrameTitle(t,event) %#ok<INUSD>
windowtitle = t.UserData;
com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.setTitle(windowtitle);

Subject: Using MLDesktop to change window title during startup

From: Jan Simon

Date: 5 Oct, 2009 21:02:18

Message: 4 of 4

Dear Albert!

> I found that 1 second was to short. Four worked fine, so i used 5 seconds for a safty margin. Here is the code I used at the bottom of my startup function:
>
> % check for previously created startup_timer
> T_existing = timerfindall('Name','startup_timer');
> if ~isempty(T_existing)
> stop(T_existing);
> delete(T_existing);
> end
> clear T_existing;
> % create timer to change the window title
> windowtitle = ['MATLAB ',version,', MyEnvir ',My_version];
> com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.setTitle(windowtitle);
> T = timer('UserData',windowtitle);
> set(T,'Name','startup_timer'); % name so we can find it later
> set(T,'TimerFcn',@setMainFrameTitle); % set timer function
> set(T,'BusyMode','queue');
> set(T,'StartDelay',5); % run 5 seconds after start
> set(T,'ObjectVisibility','off'); % hide from timerfind
> start(T); % start the timer
>
> function setMainFrameTitle(t,event) %#ok<INUSD>
> windowtitle = t.UserData;
> com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.setTitle(windowtitle);

I added a check, if Matlab was started with the JVM, before calling COM:
  if usejava('desktop')
    create timer...
  end

And I delete the TIMER object after the single shot:
  function setMainFrameTitle(t,event) %#ok<INUSD>
 windowtitle = t.UserData;
com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.setTitle(windowtitle);
  stop(t);
  delete(t);

You are right: 1 sec was too short. 2 sec worked for me for some time, but know I need 4 sec also. --- What the hell does happen in the background 3 sec after startup has finished?!

Kind regards, Jan

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
java Albert 30 Sep, 2009 14:44:13
mldesktop Albert 30 Sep, 2009 14:44:13
window title Albert 30 Sep, 2009 14:44:13
rssFeed for this Thread

Contact us at files@mathworks.com