jchooser embeded in GUI - obtain status of buttons and change to save type
3 ビュー (過去 30 日間)
古いコメントを表示
I am trying to embed a uifile load/save file dialog into another GUI, I'm having issues determining which button was pressed (load/save or cancel) and changing the "open" button to say "Save"
How can I:
1. In the ActionPerformedCallback obtain the jchooser status (i.e. which button was pressed)
2. Change the jchooser to be a save dialog rather than open.
Thanks
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.9 0.8 0.1 0.2]);
set(hPanel, 'units','normalized','position',[0 0 0.9 1.0]);
jchooser = javaObjectEDT('javax.swing.JFileChooser', pwd );
set(handle(jchooser, 'callbackproperties'),'ActionPerformedCallback', 'disp(''Action'')')
% Show the actual dialog
jPanel.add(jchooser)
0 件のコメント
採用された回答
Malcolm Lidierth
2012 年 8 月 16 日
編集済み: Malcolm Lidierth
2012 年 8 月 16 日
@Robin
Replace 'disp(''Action'')' with a callback
function callback(hObj,evt)
...
end
Within the callback, evt.getActionCommand() will give the button e.g.
evt.getActionCommand()==javax.swing.JFileChooser.APPROVE_SELECTION
will return true for the OK button and
evt.getActionCommand==javax.swing.JFileChooser.CANCEL_SELECTION
for cancel.
For dialog types use e.g.
setDialogType(javax.swing.JFileChooser.OPEN_DIALOG)
Google "grep JFileChooser" to get links to the source code for JFileChooser.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!