Following my post on Changing Matlab’s Command Window colors [1], I received an email asking whether it was possible to temporarily set the Command-Window (CW)’s text color, so that subsequent disp or fprintf commands will be displayed in some specific text color.
The short and simple answer is no: You can change the text color as described in that post, but once you modify it, the entire CW text will be modified accordingly.
Unfortunately, CW (like Swing’s standard JTextArea [2] of which CW is an instance) does not automatically support HTML formatting as most other uicontrols [3]. In fact, CW’s default Document object, which holds all the text-area’s text and font style information, is an extension of Swing’s javax.swing.text.PlainDocument [4], which does not allow any text style formatting. And the CW object itself is a simple JTextArea, which does not enable using a styled Document object. Perhaps in a future version MathWorks would be willing to use the almost identical (syntactically-wise) JTextPane [5], which does enable styled text runs.
To a very limited degree, you can use the fact that hyperlinks and error messages have separate styles than standard text (respectively, blue underlined and red). So, you can output text in these styles as follows:
% Use hyperlink style: >> disp('<a href="">my text</a>') my text % Use STDERR (fid=2) style: >> fprintf(2,'my text\n') my text
Note: you could possibly get a handle to the JTextArea (see the previous post) and then set its UI property to your tailor-made Java UI class. In this class you can set text segment properties based on whichever properties you wish. This is apparently how Matlab overcame JTextPane’s limitations: they implemented a custom com.mathworks.mde.cmdwin.CmdWinSyntaxUI class that extends javax.swing.plaf.basic.BasicTextAreaUI. But implementing such a custom UI class while retaining Matlab’s syntax-highlighting functionality is most probably very difficult and not worth the effort. So we’ll just wait for some supported method in a future Matlab release.
Addendum (May 13, 2009): I have found a way to enable display of text in any color, as well as underline, in the Command Window. See my post on cprintf [6] for details.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4