Adding callbacks to JFileChooser in embedded GUI

3 visualizaciones (últimos 30 días)
Hi, I'm trying to build a dialog with an embedded file open dialog (see code below as starting point). I'm having trouble working out how to add callbacks (listerners) to the open and cancel buttons.
I want to add a number of checkboxes to the right hand side - and if the user selects a file/files and clicks open then I want to perform specific tasks - any help on how I can do this much apprecaited.
import javax.swing.JFileChooser;
d = dialog('windowstyle', 'normal', 'position', [0 0 750 400] );
centerfig ( d )
set ( d, 'visible', 'on' );
[jPanel,hPanel] = javacomponent(javax.swing.JPanel, [], d);
hControl = uicontrol('style','checkbox', 'parent',d,'string','click me', 'units','normalized','position', [0.85 0.8 0.2 0.2]);
set(hPanel, 'units','normalized','position',[0 0 0.8 1.0]);
jchooser = javaObjectEDT('javax.swing.JFileChooser', pwd );
%%Show the actual dialog
% status = jchooser.showOpenDialog([]);

Respuesta aceptada

Malcolm Lidierth
Malcolm Lidierth el 23 de Jul. de 2012
You could install callbacks to log the state of the buttons in MATLAB so these would be available after you click 'Open' and return to MATLAB.
hControl = uicontrol('style','checkbox', 'parent',d,'string','click me', 'callback', 'disp(''State Change'')','units','normalized','position', [0.85 0.8 0.2 0.2]);
'disp(''State Change'')'
with a callback.
  3 comentarios
Malcolm Lidierth
Malcolm Lidierth el 24 de Jul. de 2012
Editada: Malcolm Lidierth el 24 de Jul. de 2012
Both buttons fire ActionPerformed events so
set(jchooser,'ActionPerformedCallback', 'disp(''Action'')')
Edit: For future reference, that would be better as:
set(handle(jchooser, 'callbackproperties'),'ActionPerformedCallback', 'disp(''Action'')')
to reduce memory leaks and MATLAB warnings on recent versions.
Robert Cumming
Robert Cumming el 1 de Ag. de 2012
Thanks for this 1 have 2 further questions.
1. How to obtain which of the actions was performed?
2. How to change the jchooser to be a save dialog rather than opendialog

Iniciar sesión para comentar.

Más respuestas (0)


Más información sobre Programming Utilities en Help Center y File Exchange.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by