【发布时间】:2016-02-26 09:09:08
【问题描述】:
我想将 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);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
【问题讨论】:
标签: java swing opengl look-and-feel