
Undocumented Secrets of MATLAB
®
-Java Programming208
Instead of using MATLAB’s uipushtool/uitoggletool, we can add JComponents directly
into our jToolbar. This is particularly useful for drop-downs (javax.swing.JComboBox),
checkboxes, and so on, which cannot be added to the toolbar using plain-vanilla MATLAB:
jToolbar = get(get(hToolbar,'JavaContainer'),'ComponentPeer');
jCheckBox = javax.swing.JCheckBox('Checkbox');
hCheckBox = handle(jCheckBox,'CallbackProperties');
set(hCheckBox, 'ActionPerformedCallback', @myCallbackFcn);
jToolbar.add(hCheckBox,5); % 5th position, after printer icon
jToolbar.revalidate;
Addition of a Java control to the standar