MouseWheelListener in JFrame that was created in java does not work

조회 수: 3 (최근 30일)
Wouter
Wouter 2011년 11월 25일
Hi all,
I have a java class with a constructor that receives some java model object. The class extends JFrame and visualizes the model. There is a MouseWheelListener to allow zooming into the model visualization.
public class myGUI extends JFrame {
public myGUI(myModelClass model) {
add(new modelCanvas(model));
}
}
public class modelCanvas extends JPanel {
private myModelClass model;
public modelCanvas(myModelClass model) {
this.model = model;
addMouseWheelListener(new myMouseWheelListener());
}
public void paintComponent(java.awt.Graphics g) {
// paints the model canvas
}
}
All works well when myGUI is invoked from java. As soon as I create a myModelClass in matlab and create a myGUI from it, 2 things happen:
  1. Look-and-feel is different, which is ok.
  2. The MouseWheelListener does not work, which renders the visualization useless.
Is there a way to circumvent the 2nd issue?
Wouter

답변 (1개)

Wouter
Wouter 2011년 11월 25일
Putting a MouseWheelListener on the JFrame instead of the JPanel inside it, and then transposing the mouse location (java.awt.Point) information did the trick. Ugly way to program the scroll=zoom function, but it does work. Still strange though.

카테고리

Help CenterFile Exchange에서 Model Predictive Control Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by