Comments on: Auto-completion widget https://undocumentedmatlab.com/blog_old/auto-completion-widget Charting Matlab's unsupported hidden underbelly Thu, 02 May 2024 08:00:01 +0000 hourly 1 https://wordpress.org/?v=4.4.1 By: Peterhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-457131 Mon, 07 Jan 2019 21:29:31 +0000 https://undocumentedmatlab.com/?p=5763#comment-457131 It seems i solved the issue i reported a couple of hours ago. I use javaObjectEDT (thanks for explaining that in your other post) on jSearchTextField before the setText invocation..

]]>
By: Peterhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-457126 Mon, 07 Jan 2019 18:34:36 +0000 https://undocumentedmatlab.com/?p=5763#comment-457126 Hi!

This is quite elegant. Unfortunately, there is a problem with Matlab hanging (matlab 2018b, windows 8.1) in the searchComboUpdated(obj, jCombo, eventData, hPanel) function. The hang occurs at jSearchTextField.setText(selectedItem). From other articles on your blog I learned that it could be EDT related and I hence added the drawnow; pause(0.1); that sometimes solves this. In this case it doesn’t help. In a newly started Matlab I get a hang everytime. It doesn’t hang in debug mode, but as soon as I run it without a breakpoint, it hangs. So frustrating.. and so unfortunate that Matlab has all these issues. I tried longer pause-times as well..didn’t help. Do you have any ideas?

Best,
Peter

PS: the code:

function searchComboUpdated(obj, jCombo, eventData, hPanel)
    ptime = 0.1;
    selectedItem = regexprep(char(jCombo.getSelectedItem),']*>','');  % strip away HTML tags
    fprintf('1');
 
    jSearchTextField = hPanel.UserData(2).getComponent(0);
    fprintf('2');
    drawnow; pause(ptime);
 
    str = java.lang.String(selectedItem);
    drawnow; pause(ptime);
    fprintf('2b');
    drawnow; pause(ptime);
 
    jSearchTextField.setText(str);
    drawnow; pause(ptime);
    fprintf('3');
    drawnow; pause(ptime);
 
    jSearchTextField.repaint; drawnow; pause(0.01);
    fprintf('4');
 
    jAssetChooser = getappdata(hPanel,'jAssetChooser');
    fprintf('5');
 
    obj.updateSearch([],[],jCombo,jAssetChooser);
    fprintf('6');
end  % searchComboUpdated
]]>
By: Stevhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-445154 Fri, 05 Oct 2018 06:03:12 +0000 https://undocumentedmatlab.com/?p=5763#comment-445154 Hello together,

I am iteressted in the same point. I can implemement

set(handle(jPanelObj,'callbackproperties'), 'ActionPerformedCallback', @myMatlabCallbackFunc);

and this works fine, but with this callback I can not trigger on return or enter.

Do anybody have an idea to this topic.

Best Regards Stev

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-426750 Tue, 22 May 2018 09:22:42 +0000 https://undocumentedmatlab.com/?p=5763#comment-426750 @Peter – My aim in this post, as in my entire blog, is to provide general guidelines, code snippets and sample output. I expect my readers to fill in the missing blanks. Admittedly, not all readers can do this, but I aim high, unapologetically. I rarely spoon-feed users with complete code programs. This would be quite beyond the scope of a typical blog post, or the amount of time that I can spend pro-bono. Remember that this blog has 400 articles, so if I had to spend a full day on each one, this would translate to almost two full work-years!

I have now added some extra code and explanations to the main text, which should be more than enough for most Matlab developers. If it’s still not enough for you, then consider asking a professional Matlab developer to assist you.

]]>
By: Peterhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-425582 Sat, 12 May 2018 23:14:22 +0000 https://undocumentedmatlab.com/?p=5763#comment-425582 This looks great but as others have pointed out, the example is incomplete. Could you provide an actual working code as the code snippets you provide does not work by them self?

Thanks.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-421561 Tue, 27 Mar 2018 17:55:40 +0000 https://undocumentedmatlab.com/?p=5763#comment-421561 @Eric – read my answer above

]]>
By: Eric Alexanderhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-421560 Tue, 27 Mar 2018 17:35:13 +0000 https://undocumentedmatlab.com/?p=5763#comment-421560 Yair,

I am trying to implement something very similar in a GUI I am making but after creating the Combo Box and running your above code, I am getting an error at the line:

assetClassIdx = getappdata(handles.cbAssetClass, 'assetClassIdx');

because there is no variable “handles.” What does this variable need to be?

]]>
By: Johanhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-401969 Sun, 05 Mar 2017 00:26:12 +0000 https://undocumentedmatlab.com/?p=5763#comment-401969 Hello Yair,

Im having a problem with getting a keypress callback on R2015b for the simpe autocompletewidget:

strs = {'This','is','test1','test2'};
strList = java.util.ArrayList;
for idx = 1 : length(strs),  strList.add(strs{idx});  end
jPanelObj = com.mathworks.widgets.AutoCompletionList(strList,'');
javacomponent(jPanelObj.getComponent, [10,10,200,100], gcf);
set(handle(jPanelObj.getComponent,'callbackproperties'), 'KeyTypedCallback', @myMatlabCallbackFunc);

I would like to have this callback to register a ‘enter’ keystroke signifying a completed selection.

Any help would be greatly appreciated!

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-397448 Fri, 23 Dec 2016 10:57:47 +0000 https://undocumentedmatlab.com/?p=5763#comment-397448 @Stefano – answering this is beyond the time that I can spend on a blog comment. You’re invited to email me (altmany at gmail) for a short consultancy on your specific program.

]]>
By: Stefanohttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-397242 Thu, 22 Dec 2016 09:47:19 +0000 https://undocumentedmatlab.com/?p=5763#comment-397242 Hi Yair,

I’m trying to implement your Autocomplete widget in my GUI (more simple than yours).
I’ve decided to split the code to better understand it, but i have two problems:

1) I can’t select the word from the combobox dropdown panel or by typing in the search text-box

How can i do that? How can i get the selected word to use it?
I’ve tried with jAssetChooser.getSearchText or jCombo.getSelectedItem but it didn’t work.
Must i use the setappdata comand?

2) If the word doesn’t match with my the list i get this Java error:

Error using provaaa/updateSearch (line 94)
Java exception occurred:
java.lang.NullPointerException
	at javax.swing.DefaultComboBoxModel.(Unknown Source)

I’m using matlab 2016a.

This is my example code:
[*** very large code section removed ***]

Thanks in advance.
Stefano

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-370260 Sun, 21 Feb 2016 15:12:32 +0000 https://undocumentedmatlab.com/?p=5763#comment-370260 @Efraim – hPanel is (of course) the panel handle that should contain the search-text field component; jCombo is the left-most combo-box that contains the asset names. If you need any assistance with getting it all to work in your specific project, consider hiring me for a short consultancy.

]]>
By: Efraïm Salarihttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-370116 Fri, 19 Feb 2016 13:51:07 +0000 https://undocumentedmatlab.com/?p=5763#comment-370116 Hi Yair,
Sorry for the unclarity. I’m making a form with edit boxes which people need to fill out.
I would like to show underneath the edit box some suggestions of commonly used input, based on what somebody is typing. However, like you suggested, I copied your code in my Matlab and tried to run it. I got two errors: The variables hPanel and jCombo could not be found. I went through all your code on this page but these two variables are not created. Do I need some code from another page maybe(e.g. where you explain the Editable combo-box)?

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-370083 Thu, 18 Feb 2016 17:27:43 +0000 https://undocumentedmatlab.com/?p=5763#comment-370083 @Efraim – I’m not sure what you want. I showed exactly how to do this in the main article above. If you did not understand my code then try to read it carefully and test the code in your Matlab, step-by-step. Good luck!

]]>
By: Efraïm Salarihttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-370077 Thu, 18 Feb 2016 16:17:39 +0000 https://undocumentedmatlab.com/?p=5763#comment-370077 Hi Yair,
I’m looking for an edit box which gives suggestions of what you might want to type (It’s a form that people need to fill out), but is not limited to the predefined options. I was thinking the auto-completion function might be an option (or are there other options for this?).

I tried to go through your code but it seems I missed something. The variables hPanel and jCombo could not be found. Is there some code I missed?

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-359829 Mon, 26 Oct 2015 08:31:58 +0000 https://undocumentedmatlab.com/?p=5763#comment-359829 @Rami – This blog discusses advanced Matlab topics, which are typically way beyond the basics. GUIDE only includes basic controls in its designer. However, you can add any control, including all the ones that I highlight in this blog, within the m-file that is generated by GUIDE. Advanced Matlab users often find that it becomes easier to generate the entire GUI by hand, without using GUIDE at all, but you can add the advanced controls in either. The upcoming AppDesigner will include more advanced controls than GUIDE, but there will always be a place for custom-made GUIs for professional appearance and functionality.

In the 2 code rows you provided, the first command created the Java component jPanelObj, and the second command placed this component in the GUI figure using the javacomponent function.

If you wish to learn more about creating advanced Matlab GUIs and/or working with Java in Matlab, get my Matlab-Java book. If you have a commercial need, consider hiring me for a consulting project.

]]>
By: Ramihttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-359682 Sat, 24 Oct 2015 21:51:47 +0000 https://undocumentedmatlab.com/?p=5763#comment-359682 Hello,

I’m trying to implement simple Auto Completion box in my simplistic GUI. And I have few Questions as a newbie to this area. I hope you would be patient enough to help me.

1. Can I implement these objects in my GUIDE built GUI? I started with GUIDE since it’s very easy to start going with. But I found that I don’t have this component. So How I get along?
2. As a follow-up to the last question, should I try to program my GUI from scratch? what are the advantages compared to the workload of creating everything manually?
3. Can you explain what each of the following commands in your example mean? I read your javacomponent article but I don’t understand how each argument affects the output.

jPanelObj = com.mathworks.widgets.AutoCompletionList(strList,'');
javacomponent(jPanelObj.getComponent, [10,10,200,100], gcf);

4. While playing around I tried to update the list. Updating the array was easy but I couldn’t find the object / property to update nor any proper update function to use. I tried different get options but it didn’t get me far enough.

Thanks,
Rami

]]>
By: ikchttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-351393 Tue, 16 Jun 2015 14:24:30 +0000 https://undocumentedmatlab.com/?p=5763#comment-351393 @Yair
Thank you for your reply.
I think I have figured out how it works.
This could be a fancy search method we can use in MATLAB.

However,
I still encounter the Java OutOfMemory Error.
My MATLAB Java Heap Memory is 384 MB (Default).

What my Java script doing here is reading the description from the database and display the description on the GUI.
When user press and release the down arrow on the keyboard, selection will be moved to next item and description will be updated.
The challenge is, when user holding the down arrow, selection will be moved to next item very quickly, but the description update speed can’t catch up with the selection move speed.
I am using the following statement to capture the memory usage.

free = java.lang.Runtime.getRuntime.freeMemory
total = java.lang.Runtime.getRuntime.totalMemory
max = java.lang.Runtime.getRuntime.maxMemory

I can see the Java is consuming a ton of memory.
Do you have any thought on releasing the Java memory or only way we can do is increasing the heap size?

Thanks a lot.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-351114 Thu, 11 Jun 2015 10:39:21 +0000 https://undocumentedmatlab.com/?p=5763#comment-351114 @ikc – here’s a pared-down code-snippet that explains how cbAssetClass was created:

function createMainGUI()
   ...
   handles.cbAssetClass = createComboSelector(hPanel, ['All'; assetClassNames], @assetClassUpdatedCallback, false);
   ...
end
 
function hContainer = createComboSelector(hParent, strings, callback, isEditable)
   % Note: MJComboBox is better than JComboBox: the popup panel has more width than the base control if needed
   jComboBox = com.mathworks.mwswing.MJComboBox(strings);  % =javax.swing.JComboBox(strings);
   jComboBox.setEditable(isEditable);
   jComboBox.setBackground(java.awt.Color.white); % unfortunately, this only affects editable combos
   ...  % fixing the gray bgcolor of non-editable combos
   [jhComboBox, hContainer] = javacomponent(jComboBox, [], hParent);
   set(jhComboBox, 'ActionPerformedCallback', callback);
   hContainer = handle(hContainer);
   set(hContainer, 'tag','hAssetContainer', 'UserData',jComboBox);
end
]]>
By: ikchttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-351076 Wed, 10 Jun 2015 21:35:55 +0000 https://undocumentedmatlab.com/?p=5763#comment-351076 Thank you for your post.
I am using combobox and editbox to do the same thing right now. However, Matlab will report
java.lang.OutOfMemoryError: GC overhead limit exceeded

So I am looking for another solution to approach my goal.
I try to reproduce your code on my machine. But I have question on the following statement.

assetClassIdx = getappdata(handles.cbAssetClass, 'assetClassIdx');

What is “handles” here for? jCombo? jAssetChooser? Or something else?

]]>
By: Malcolm Lidierthhttps://undocumentedmatlab.com/blog_old/auto-completion-widget#comment-348863 Wed, 06 May 2015 00:18:41 +0000 https://undocumentedmatlab.com/?p=5763#comment-348863 @Ulrik

You can upgrade Java by copying the Java 8 JRE to your MATLAB app folder with many fewer problems than occurred with Java 6 -> Java 7.

To enable JavaFX, add javafxrt.jar (from the JRE) to your Java path using javaaddpath, then create an instance of javafx.embed.swing.JFXPanel. This will cause the JRE to do the work for you and initialise the JavaFX application thread.

If you create a JavaFX application, be sure to prevent javafx.application.Platform.exit() being called when you close it. The JavaFX thread will not robustly initialise twice in a given MATLAB instance. See https://docs.oracle.com/javase/8/javafx/api/javafx/application/Platform.html

There are threading issues between the the AWT/Swing EDT and the JavaFX application thread but I understand that these have been reduced for contents of a JFXPanel in the latest Java 8 releases. JFXPanel is a Swing component able to display JavaFX and can be added to a MATLAB GUI using javacomponent (or Yair’s uicomponent or my jcontrol, which build on that).

M

]]>