Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem using tab panels and java text area

Subject: Problem using tab panels and java text area

From: dimos tsag

Date: 15 Dec, 2009 17:51:01

Message: 1 of 9

Hi.
I am building a gui and I use matlab's uitabgroup and uitab to create tabs. In each tab I want to add a text area to show some text. Since I don't want the text to warp (as is the case with matlab's ui edit) but rather have a horizontal slider as well, I tried to use Yair Altman's uicomponent to add a java textarea in each tab when it is created.

The problem is that after creation, when I try to change the tab, the text area does not change. It remains the same for all tabs and shows the text that I have entered for the last created one.

Do you know why and how I can resolve this?
Thanks.
Dimos

Subject: Problem using tab panels and java text area

From: dimos tsag

Date: 15 Dec, 2009 19:24:02

Message: 2 of 9

I have written a simple code to make my question more clear. It requires the uicomponent.m to run.

function asd
    fh = figure
    httg = uitabgroup('v0',fh);
    th1 = uitab('v0', httg, 'title', 'tab 1');
    Edit1=uicomponent(th1,'Position',[0 0 100 100],'Style','textarea');
    set(Edit1,'Text','textarea 1')
    th2 = uitab('v0', httg, 'title', 'tab 2');
    Edit2=uicomponent(th2,'Position',[100 100 100 100],'Style','textarea');
    set(Edit2,'Text','textarea 2')
end

As you will see, the problem is that the jtextarea does not become invisible when its tab in not active.

Subject: Problem using tab panels and java text area

From: Yair Altman

Date: 16 Dec, 2009 08:33:18

Message: 3 of 9

"Dimos Tsag" <dimostsag@gmail.com> wrote in message <hg8noi$1b7$1@fred.mathworks.com>...
> I have written a simple code to make my question more clear. It requires the uicomponent.m to run.
>
> function asd
> fh = figure
> httg = uitabgroup('v0',fh);
> th1 = uitab('v0', httg, 'title', 'tab 1');
> Edit1=uicomponent(th1,'Position',[0 0 100 100],'Style','textarea');
> set(Edit1,'Text','textarea 1')
> th2 = uitab('v0', httg, 'title', 'tab 2');
> Edit2=uicomponent(th2,'Position',[100 100 100 100],'Style','textarea');
> set(Edit2,'Text','textarea 2')
> end
>
> As you will see, the problem is that the jtextarea does not become invisible when its tab in not active.

This is a known issue with uitab/uitabgroup, that has already been reported several times in the past. It affects ActiveX ( http://tinyurl.com/3dgwar ) and Java
( http://tinyurl.com/2o2j8e ) components. MathWorks has not seen fit to fix this, possibly since uitab remains unsupported.

The reason for the bug is related to the fact that the uitabs are really a visual deception: only the tab row is an actual Java object, whereas the container area is a Matlab uicontainer. Matlab uses very clever double-booking to keep the Java and Matlab objects synchronized. The ability to "switch" tabs is a deception: in reality, a listener placed on the SelectedIndex property of the tab group causes the relevant Matlab container to display and all the rest to become hidden. Other listeners control the containers' position and size based on the tab group's. Adding and removing tabs uses similar methods to add/remove empty tabs to the JTabbedPane. Check the code within %MATLABROOT%\toolbox\matlab\@uitools\@uitabgroup\schema.m to see how this is done.

To solve the problem, I've used two methods:

1. Use an actual JTabbedPane object and embed your JTable object(s) within its tab(s). This pure-Java solution works well as long as you don't need to embed Matlab controls or axes in any of the tabs.

2. Hook onto the uitabgroup's SelectionChangeFcn() callback and modify your uitable's Visible property accordingly

(a long answer to a simple question - hope people find the
extra info useful)

Yair Altman
http://UndocumentedMatlab.com

Subject: Problem using tab panels and java text area

From: dimos tsag

Date: 16 Dec, 2009 13:46:05

Message: 4 of 9

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hga60e$ckv$1@fred.mathworks.com>...
> "Dimos Tsag" <dimostsag@gmail.com> wrote in message <hg8noi$1b7$1@fred.mathworks.com>...
> > I have written a simple code to make my question more clear. It requires the uicomponent.m to run.
> >
> > function asd
> > fh = figure
> > httg = uitabgroup('v0',fh);
> > th1 = uitab('v0', httg, 'title', 'tab 1');
> > Edit1=uicomponent(th1,'Position',[0 0 100 100],'Style','textarea');
> > set(Edit1,'Text','textarea 1')
> > th2 = uitab('v0', httg, 'title', 'tab 2');
> > Edit2=uicomponent(th2,'Position',[100 100 100 100],'Style','textarea');
> > set(Edit2,'Text','textarea 2')
> > end
> >
> > As you will see, the problem is that the jtextarea does not become invisible when its tab in not active.
>
> This is a known issue with uitab/uitabgroup, that has already been reported several times in the past. It affects ActiveX ( http://tinyurl.com/3dgwar ) and Java
> ( http://tinyurl.com/2o2j8e ) components. MathWorks has not seen fit to fix this, possibly since uitab remains unsupported.
>
> The reason for the bug is related to the fact that the uitabs are really a visual deception: only the tab row is an actual Java object, whereas the container area is a Matlab uicontainer. Matlab uses very clever double-booking to keep the Java and Matlab objects synchronized. The ability to "switch" tabs is a deception: in reality, a listener placed on the SelectedIndex property of the tab group causes the relevant Matlab container to display and all the rest to become hidden. Other listeners control the containers' position and size based on the tab group's. Adding and removing tabs uses similar methods to add/remove empty tabs to the JTabbedPane. Check the code within %MATLABROOT%\toolbox\matlab\@uitools\@uitabgroup\schema.m to see how this is done.
>
> To solve the problem, I've used two methods:
>
> 1. Use an actual JTabbedPane object and embed your JTable object(s) within its tab(s). This pure-Java solution works well as long as you don't need to embed Matlab controls or axes in any of the tabs.
>
> 2. Hook onto the uitabgroup's SelectionChangeFcn() callback and modify your uitable's Visible property accordingly
>
> (a long answer to a simple question - hope people find the
> extra info useful)
>
> Yair Altman
> http://UndocumentedMatlab.com

Thanks very much for the reply (and also for the extremely useful files you upload). Since posting the message I was trying to find a solution and I also ended up using the SelectionChangeFcn().
For future reference, my code looks like this:

function tab_SelectionChangeFcn(src,evt)
        oldtabindex = evt.OldValue;
        newtabindex = evt.NewValue;
        changetab(src,oldtabindex,newtabindex)
end

function changetab(tabgroup,oldtabindex,newtabindex)

        if oldtabindex == 0
            return
        end
        if oldtabindex == newtabindex
            return
        end

        ch=get(tabgroup,'Children');
        
        if oldtabindex > size(ch,1)
            ;
        else
            oldtab = ch(oldtabindex);
            chop = get(oldtab,'Children');
            cho = get(chop,'Children');
            oldjt = findobj(cho,'Tag','java.awt.TextArea');
            set(oldjt,'Visible','Off')
        end

        newtab = ch(newtabindex);
        chnp = get(newtab,'Children');
        chn = get(chnp,'Children');
        newjt = findobj(chn,'Tag','java.awt.TextArea');
        if isempty(newjt)
            return
        end
        set(newjt,'Visible','On')
         drawnow
end

Subject: Problem using tab panels and java text area

From: dimos tsag

Date: 17 Dec, 2009 05:24:04

Message: 5 of 9

Hi Yair. I am in need of help once more, and before opening a new thread, I hope you will see and reply to this.
As I said above, I used the uicomponent to create a textarea. I am trying to change its font but with no success.
What I have done until now is to take the JavaComponent handle and try to use the setFont.
When I enter the getFont I get this
jav.getFont
 ans =
 javax.swing.plaf.FontUIResource[family=Tahoma,name=Tahoma,style=plain,size=11]

But when I try for example
jav.setFont('new Font("Serif", Font.ITALIC, 16)');
matlab issues no error but the font doesn't change (I confirmed it with getFont).

Since I know really few things about java, I can't tell what's wrong.
Any help would be much appreciated.
Thanks again.
Dimos

Subject: Problem using tab panels and java text area

From: dimos tsag

Date: 17 Dec, 2009 05:28:03

Message: 6 of 9

I forgot to mention that I want to change the font in order to use a Fixed-Width Font, like Courier New.

Subject: Problem using tab panels and java text area

From: Yair Altman

Date: 17 Dec, 2009 23:05:24

Message: 7 of 9

"Dimos Tsag" <dimostsag@gmail.com> wrote in message <hgcf9k$kf1$1@fred.mathworks.com>...
> Hi Yair. I am in need of help once more, and before opening a new thread, I hope you will see and reply to this.
> As I said above, I used the uicomponent to create a textarea. I am trying to change its font but with no success.
> What I have done until now is to take the JavaComponent handle and try to use the setFont.
> When I enter the getFont I get this
> jav.getFont
> ans =
> javax.swing.plaf.FontUIResource[family=Tahoma,name=Tahoma,style=plain,size=11]
>
> But when I try for example
> jav.setFont('new Font("Serif", Font.ITALIC, 16)');
> matlab issues no error but the font doesn't change (I confirmed it with getFont).
>
> Since I know really few things about java, I can't tell what's wrong.
> Any help would be much appreciated.
> Thanks again.
> Dimos


I could spoon-feed you the solution but it's better if you read and try this yourself: http://javatechniques.com/blog/setting-jtextpane-font-and-color/

Yair Altman
http://UndocumentedMatlab.com

Subject: Problem using tab panels and java text area

From: Yair Altman

Date: 17 Dec, 2009 23:11:06

Message: 8 of 9

Also read these related articles from the official Java tutorial:
http://java.sun.com/docs/books/tutorial/uiswing/components/text.html
http://java.sun.com/docs/books/tutorial/uiswing/components/textarea.html
http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html

Yair Altman
http://UndocumentedMatlab.com
 

Subject: Problem using tab panels and java text area

From: Audrey

Date: 3 Feb, 2010 22:58:04

Message: 9 of 9

I have some trouble to use the uitab in Linux. It works fine in Windows. But in Linux, it is going to display every tab and every control in the tab, creating a flash. In windows, it will only display the first tab.

I have tried to set the tab property 'Visible', to 'off'. It works in Windows, but not in Linux.

Can anyone provide some suggestion?


"Dimos Tsag" <dimostsag@gmail.com> wrote in message <hgaoat$np2$1@fred.mathworks.com>...
> "Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hga60e$ckv$1@fred.mathworks.com>...
> > "Dimos Tsag" <dimostsag@gmail.com> wrote in message <hg8noi$1b7$1@fred.mathworks.com>...
> > > I have written a simple code to make my question more clear. It requires the uicomponent.m to run.
> > >
> > > function asd
> > > fh = figure
> > > httg = uitabgroup('v0',fh);
> > > th1 = uitab('v0', httg, 'title', 'tab 1');
> > > Edit1=uicomponent(th1,'Position',[0 0 100 100],'Style','textarea');
> > > set(Edit1,'Text','textarea 1')
> > > th2 = uitab('v0', httg, 'title', 'tab 2');
> > > Edit2=uicomponent(th2,'Position',[100 100 100 100],'Style','textarea');
> > > set(Edit2,'Text','textarea 2')
> > > end
> > >
> > > As you will see, the problem is that the jtextarea does not become invisible when its tab in not active.
> >
> > This is a known issue with uitab/uitabgroup, that has already been reported several times in the past. It affects ActiveX ( http://tinyurl.com/3dgwar ) and Java
> > ( http://tinyurl.com/2o2j8e ) components. MathWorks has not seen fit to fix this, possibly since uitab remains unsupported.
> >
> > The reason for the bug is related to the fact that the uitabs are really a visual deception: only the tab row is an actual Java object, whereas the container area is a Matlab uicontainer. Matlab uses very clever double-booking to keep the Java and Matlab objects synchronized. The ability to "switch" tabs is a deception: in reality, a listener placed on the SelectedIndex property of the tab group causes the relevant Matlab container to display and all the rest to become hidden. Other listeners control the containers' position and size based on the tab group's. Adding and removing tabs uses similar methods to add/remove empty tabs to the JTabbedPane. Check the code within %MATLABROOT%\toolbox\matlab\@uitools\@uitabgroup\schema.m to see how this is done.
> >
> > To solve the problem, I've used two methods:
> >
> > 1. Use an actual JTabbedPane object and embed your JTable object(s) within its tab(s). This pure-Java solution works well as long as you don't need to embed Matlab controls or axes in any of the tabs.
> >
> > 2. Hook onto the uitabgroup's SelectionChangeFcn() callback and modify your uitable's Visible property accordingly
> >
> > (a long answer to a simple question - hope people find the
> > extra info useful)
> >
> > Yair Altman
> > http://UndocumentedMatlab.com
>
> Thanks very much for the reply (and also for the extremely useful files you upload). Since posting the message I was trying to find a solution and I also ended up using the SelectionChangeFcn().
> For future reference, my code looks like this:
>
> function tab_SelectionChangeFcn(src,evt)
> oldtabindex = evt.OldValue;
> newtabindex = evt.NewValue;
> changetab(src,oldtabindex,newtabindex)
> end
>
> function changetab(tabgroup,oldtabindex,newtabindex)
>
> if oldtabindex == 0
> return
> end
> if oldtabindex == newtabindex
> return
> end
>
> ch=get(tabgroup,'Children');
>
> if oldtabindex > size(ch,1)
> ;
> else
> oldtab = ch(oldtabindex);
> chop = get(oldtab,'Children');
> cho = get(chop,'Children');
> oldjt = findobj(cho,'Tag','java.awt.TextArea');
> set(oldjt,'Visible','Off')
> end
>
> newtab = ch(newtabindex);
> chnp = get(newtab,'Children');
> chn = get(chnp,'Children');
> newjt = findobj(chn,'Tag','java.awt.TextArea');
> if isempty(newjt)
> return
> end
> set(newjt,'Visible','On')
> drawnow
> end

Tags for this Thread

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.

Contact us