我想将 Swing 与 Java2D OpenGL 图形加速一起使用。然而,它不起作用。
我自己回答了这个问题,因为我寻找解决方案很长一段时间。
这是我的代码:
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class OpenGLTest {
public static void main(String[] args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException {
// set system look and feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// activate opengl
System.setProperty("sun.java2d.opengl", "true");
// create and show the GUI in the event dispatch thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
JFrame frame = new JFrame();
frame.setTitle("OpenGL Test");
frame.setSize(400, 300); …
Run Code Online (Sandbox Code Playgroud)