问题
Code where I try to integrate shortened version of Altman's MATLAB 2013 polar radar system code into MATLAB 2016b polarxes implementation because I want to have black background in toolbar and zoom feature with horiozontal scrollbar.
The former code basically uses javax.swing.JSlider
having a continuous-movement callback
.
The current bug comes from the line 'StateChangedCallback',{@cbSlider,fp,imax});
where axes imax
does not behave as expected
close all; clear all; clc;
% http://stackoverflow.com/q/40030096/54964
fp=figure('Name', 'Test', ...
'Position',[200 200 851 404],'Resize','off'); % only half circle in polaraxes although warp can do eclipses
ThetaTicks = 0*pi:pi/10:1*pi;
pax = polaraxes( 'ThetaAxisUnits', 'radians', ...
'ThetaLim',[min(ThetaTicks) max(ThetaTicks)],...
'Color','none',...
'GridAlpha',1,...
'GridColor',[1 1 1],...
'ThetaTick', ThetaTicks, ...
'ThetaDir', 'counterclockwise', ...
'Parent', fp);
af = figure('Name', 'Do Not Touch');
testImage = 'peppers.png';
imax = axes('Parent', fp, 'Visible', 'off');
I = imread(testImage);
angleRadians=-pi;
[x, y, z]=makePolar(I, angleRadians);
fp=figure(fp);
imax.Children = warp(x, y, z, I);
set(imax,'view',[-180 -90],'Visible','off');
axis(imax,'tight')
pause(1);
%% Change toolbar bakcgrounds black like radar systems
% http://undocumentedmatlab.com/blog/customizing-figure-toolbar-background
[jSlider,hSlider] = javacomponent('javax.swing.JSlider',[0,0,.01,0.1],fp);
set(hSlider, 'Units','norm','pos',[.15,0,.7,.05]);
set(jSlider, 'Background',java.awt.Color.black, ...
'Value',0, 'Maximum',duration, ...
'StateChangedCallback',{@cbSlider,fp,imax});
hToolbar = findall(fp,'tag','FigureToolBar');
% required to programmatically alter the figure
delete(findall(hToolbar,'tag','Plottools.PlottoolsOn'))
delete(findall(hToolbar,'tag','Plottools.PlottoolsOff'))
delete(findall(hToolbar,'tag','Annotation.InsertColorbar'))
delete(findall(hToolbar,'tag','DataManager.Linking'))
delete(findall(hToolbar,'tag','Standard.EditPlot'))
% ensure the toolbar is visible onscreen
drawnow;
% Get the underlying JToolBar component
jToolbar = get(get(hToolbar,'JavaContainer'),'ComponentPeer');
% Set the bgcolor to black
color = java.awt.Color.black;
jToolbar.setBackground(color);
jToolbar.getParent.getParent.setBackground(color);
Output where I am not sure which array it is about
Error using javahandle_withcallbacks.javax.swing.JSlider/set
Array must be numeric or logical.
Error in test_polar_radar_system (line 33)
set(jSlider, 'Background',java.awt.Color.black, ...
Fig. 1 Current output where the horizontal scrolling bar works but has no successful bind to action, Fig. 2 Expected output = half circle of Altman's output but with the test image and axis starting point like in Fig. 1 but everything else can be like Altman's
Attempt 2 unsuccessfully
% https://se.mathworks.com/matlabcentral/newsreader/view_thread/164766
color = java.awt.Color.blue;
color = java.awt.Color(0,0,0.9); % alternative declaration
hToolbar=findall(gcf,'tag','FigureToolBar');
jToolbar=get(get(hToolbar,'JavaContainer'),'ComponentPeer');
jToolbar.setBackground(color)
Output
Struct contents reference from a non-struct array object.
Error in make_sample (line 822)
jToolbar.setBackground(color)
MATLAB: 2016b
OS: Debian 8.5 64 bit
Hardware: Asus Zenbook UX303UA
Linux kernel: 4.6 backports
回答1:
Your bug is probably not in setting the StateChangedCallback
but in setting the Maximum
i.e., instead of providing a simple number you probably have something else in your duration
variable. Because of this the entire set()
command fails and the StateChangedCallback
is not assigned.
来源:https://stackoverflow.com/questions/40086038/how-to-integrate-java-swing-black-background-toolbar-into-polaraxes