Java 当鼠标在MATLAB中传递静态文本时更改鼠标轨迹

Java 当鼠标在MATLAB中传递静态文本时更改鼠标轨迹,java,matlab,user-interface,text,matlab-guide,Java,Matlab,User Interface,Text,Matlab Guide,我想在鼠标位于静态文本上时更改鼠标光标(不要单击它,只更改静态文本区域)。我在未记录的matlab中找到了这些java代码: jb = javax.swing.JButton; jb.setCursor(java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); 我在静态文本的CreareFcn和ButtonDownFcn中复制了这些代码,但没有任何更改,所有内容都是默认的。如何执行此操作,以及应将这些代码放在静态文本中的何处 谢谢。您可以使用鼠标运动监听器实

我想在鼠标位于
静态文本上时更改鼠标光标(不要单击它,只更改静态文本区域)。我在
未记录的matlab中找到了这些java代码:

jb = javax.swing.JButton;
jb.setCursor(java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
我在
静态文本的
CreareFcn
ButtonDownFcn
中复制了这些代码,但没有任何更改,所有内容都是默认的。如何执行此操作,以及应将这些代码放在
静态文本中的何处


谢谢。

您可以使用鼠标运动监听器实现这一点,如下所示:

function init()
  %// Initialize the figure with a listener:
  h = figure('WindowButtonMotionFcn',@windowMotion,'Pos',[400,400,200,200]);
  %// Add a "static" text label:
  col = get(h,'color');
  lbl = uicontrol('Style','text', 'Pos',[10,160,120,20], ...
                  'Background',col, 'HorizontalAlignment','left');
  drawnow;
  setptr(gcf, 'fleur'); %// Optional, set default pointer.

function windowMotion(varargin)
    cursor_pos = get(h,'CurrentPoint');
    set(lbl,'String',sprintf('Mouse position: %d, %d',cursor_pos));
    drawnow;

    pos = get(lbl,'position'); %// This doesn't need to happen every time, 
                               %// it's here for the sake of demonstration.
    if (cursor_pos(1)>pos(1) && cursor_pos(1)<pos(1)+pos(3)) && ...
       (cursor_pos(2)>pos(2) && cursor_pos(2)<pos(2)+pos(4)) 
       setptr(gcf, 'hand'); %// Change to this cursor if pointer is inside
                            %// the element.
    else
       setptr(gcf, 'fleur'); %//otherwise (re)change to default
    end

  end

end
函数init()
%//使用侦听器初始化图形:
h=图形('WindowButtonMotionFcn',@windowMotion,'Pos',[400200200]);
%//添加“静态”文本标签:
col=get(h,'color');
lbl=uicontrol('Style','text','Pos',[10160120,20]。。。
“背景”,col,“水平对齐”,“左”);
现在抽;
setptr(gcf,'fleur');%//可选,设置默认指针。
函数windowMotion(varargin)
光标_pos=get(h,'CurrentPoint');
设置(lbl,'String',sprintf('鼠标位置:%d,%d',光标位置));
现在抽;
pos=get(lbl,'position');%//这不需要每次都发生,
%//这里是为了演示。

如果(光标位置(1)>pos(1)&&cursor位置(1)pos(2)&&cursor位置(2),您可以使用鼠标运动监听器实现这一点,如下所示:

function init()
  %// Initialize the figure with a listener:
  h = figure('WindowButtonMotionFcn',@windowMotion,'Pos',[400,400,200,200]);
  %// Add a "static" text label:
  col = get(h,'color');
  lbl = uicontrol('Style','text', 'Pos',[10,160,120,20], ...
                  'Background',col, 'HorizontalAlignment','left');
  drawnow;
  setptr(gcf, 'fleur'); %// Optional, set default pointer.

function windowMotion(varargin)
    cursor_pos = get(h,'CurrentPoint');
    set(lbl,'String',sprintf('Mouse position: %d, %d',cursor_pos));
    drawnow;

    pos = get(lbl,'position'); %// This doesn't need to happen every time, 
                               %// it's here for the sake of demonstration.
    if (cursor_pos(1)>pos(1) && cursor_pos(1)<pos(1)+pos(3)) && ...
       (cursor_pos(2)>pos(2) && cursor_pos(2)<pos(2)+pos(4)) 
       setptr(gcf, 'hand'); %// Change to this cursor if pointer is inside
                            %// the element.
    else
       setptr(gcf, 'fleur'); %//otherwise (re)change to default
    end

  end

end
函数init()
%//使用侦听器初始化图形:
h=图形('WindowButtonMotionFcn',@windowMotion,'Pos',[400200200]);
%//添加“静态”文本标签:
col=get(h,'color');
lbl=uicontrol('Style','text','Pos',[10160120,20]。。。
“背景”,col,“水平对齐”,“左”);
现在抽;
setptr(gcf,'fleur');%//可选,设置默认指针。
函数windowMotion(varargin)
光标_pos=get(h,'CurrentPoint');
设置(lbl,'String',sprintf('鼠标位置:%d,%d',光标位置));
现在抽;
pos=get(lbl,'position');%//这不需要每次都发生,
%//这里是为了演示。

如果(光标位置(1)>pos(1)&&cursor位置(1)pos(2)&&cursor位置(2),您可以使用鼠标运动监听器实现这一点,如下所示:

function init()
  %// Initialize the figure with a listener:
  h = figure('WindowButtonMotionFcn',@windowMotion,'Pos',[400,400,200,200]);
  %// Add a "static" text label:
  col = get(h,'color');
  lbl = uicontrol('Style','text', 'Pos',[10,160,120,20], ...
                  'Background',col, 'HorizontalAlignment','left');
  drawnow;
  setptr(gcf, 'fleur'); %// Optional, set default pointer.

function windowMotion(varargin)
    cursor_pos = get(h,'CurrentPoint');
    set(lbl,'String',sprintf('Mouse position: %d, %d',cursor_pos));
    drawnow;

    pos = get(lbl,'position'); %// This doesn't need to happen every time, 
                               %// it's here for the sake of demonstration.
    if (cursor_pos(1)>pos(1) && cursor_pos(1)<pos(1)+pos(3)) && ...
       (cursor_pos(2)>pos(2) && cursor_pos(2)<pos(2)+pos(4)) 
       setptr(gcf, 'hand'); %// Change to this cursor if pointer is inside
                            %// the element.
    else
       setptr(gcf, 'fleur'); %//otherwise (re)change to default
    end

  end

end
函数init()
%//使用侦听器初始化图形:
h=图形('WindowButtonMotionFcn',@windowMotion,'Pos',[400200200]);
%//添加“静态”文本标签:
col=get(h,'color');
lbl=uicontrol('Style','text','Pos',[10160120,20]。。。
“背景”,col,“水平对齐”,“左”);
现在抽;
setptr(gcf,'fleur');%//可选,设置默认指针。
函数windowMotion(varargin)
光标_pos=get(h,'CurrentPoint');
设置(lbl,'String',sprintf('鼠标位置:%d,%d',光标位置));
现在抽;
pos=get(lbl,'position');%//这不需要每次都发生,
%//这里是为了演示。

如果(光标位置(1)>pos(1)&&cursor位置(1)pos(2)&&cursor位置(2),您可以使用鼠标运动监听器实现这一点,如下所示:

function init()
  %// Initialize the figure with a listener:
  h = figure('WindowButtonMotionFcn',@windowMotion,'Pos',[400,400,200,200]);
  %// Add a "static" text label:
  col = get(h,'color');
  lbl = uicontrol('Style','text', 'Pos',[10,160,120,20], ...
                  'Background',col, 'HorizontalAlignment','left');
  drawnow;
  setptr(gcf, 'fleur'); %// Optional, set default pointer.

function windowMotion(varargin)
    cursor_pos = get(h,'CurrentPoint');
    set(lbl,'String',sprintf('Mouse position: %d, %d',cursor_pos));
    drawnow;

    pos = get(lbl,'position'); %// This doesn't need to happen every time, 
                               %// it's here for the sake of demonstration.
    if (cursor_pos(1)>pos(1) && cursor_pos(1)<pos(1)+pos(3)) && ...
       (cursor_pos(2)>pos(2) && cursor_pos(2)<pos(2)+pos(4)) 
       setptr(gcf, 'hand'); %// Change to this cursor if pointer is inside
                            %// the element.
    else
       setptr(gcf, 'fleur'); %//otherwise (re)change to default
    end

  end

end
函数init()
%//使用侦听器初始化图形:
h=图形('WindowButtonMotionFcn',@windowMotion,'Pos',[400200200]);
%//添加“静态”文本标签:
col=get(h,'color');
lbl=uicontrol('Style','text','Pos',[10160120,20]。。。
“背景”,col,“水平对齐”,“左”);
现在抽;
setptr(gcf,'fleur');%//可选,设置默认指针。
函数windowMotion(varargin)
光标_pos=get(h,'CurrentPoint');
设置(lbl,'String',sprintf('鼠标位置:%d,%d',光标位置));
现在抽;
pos=get(lbl,'position');%//这不需要每次都发生,
%//这里是为了演示。

if(cursor_pos(1)>pos(1)&&cursor_pos(1)pos(2)&&cursor_pos(2)谢谢您的回答。我应该在哪里插入此代码?我正在使用
指南
。再次感谢您的帮助:-)谢谢您的回答。我应该在哪里插入此代码?我正在使用
指南
。再次感谢您的帮助:-)谢谢您的回答。我应该在哪里插入此代码?我正在使用
指南
。再次感谢您的帮助:-)谢谢您的回答。我应该在哪里插入此代码?我正在使用
指南
。再次感谢您的帮助:-)