如果我直接使用vlcj来显示全屏然后就可以了,但是当我最初设置一个固定的大小然后在飞行中将它设置为全屏然后它丢失了它的渲染, 代码:
panel_canvas=new JPanel(new BorderLayout());
panel_canvas.add(windowsCanvas,BorderLayout.CENTER);
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show");
mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
mediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(windowsCanvas));
frame.setContentPane(panel_canvas);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setSize(600,500);
frame.setVisible(true);
但如果按“输入”时我使用了一个过程,它将全屏显示然后失败
frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released ENTER"), "RELEASED_ENTER");
frame.getRootPane().getActionMap().put("RELEASED_ENTER", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if(!frame.isUndecorated()){
pres_size=frame.getSize();
prev_location=frame.getLocation();
frame.dispose();
frame.setUndecorated(true);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setVisible(true);
}
答案 0 :(得分:1)
我在代码中应用以下方法在Swing中切换全屏:
int lastState = 0;
Rectangle lastBounds = null;
private void toggleDecoration(boolean decorated) {
dispose();
if (decorated) {
//save last bounds and its extended state
lastState = getExtendedState();
lastBounds = getBounds();
try{
setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
}
catch(Exception ev){
setBounds(getGraphicsConfiguration().getDevice().getDefaultConfiguration().getBounds());
ev.printStackTrace();
}
}
else {
//restore last bounds and its extended state
setBounds(lastBounds);
setExtendedState(lastState);
}
setUndecorated(decorated);
setVisible(true);
}
用法:
decorated = !decorated;
toggleDecoration(decorated);
答案 1 :(得分:1)
我遇到了同样的问题,并以这种方式解决了:
@SuppressWarnings("deprecation")
public static void toogleFullScreen(JFrame mainWindow) {
boolean isPlaying = mainWindow.mediaPlayer.isPlaying();
if (isPlaying) {
mainWindow.mediaPlayer.stop();
}
if (!mainWindow.isUndecorated()) {
mainWindow.dispose();
mainWindow.setAlwaysOnTop(true);
mainWindow.setUndecorated(true);
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().setFullScreenWindow(mainWindow);
BufferedImage cursorImage = new BufferedImage(1, 1,
Transparency.TRANSLUCENT);
mainWindow.setCursor(Toolkit.getDefaultToolkit()
.createCustomCursor(cursorImage, new Point(0, 0),
"InvisibleCursor"));
mainWindow.setVisible(true);
mainWindow.repaint();
} else {
GraphicsDevice device = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode modo = device.getDisplayMode();
mainWindow.dispose();
mainWindow.setAlwaysOnTop(false);
mainWindow.setUndecorated(false);
mainWindow.setBounds(modo.getWidth() / 2, modo.getHeight() / 2,
modo.getWidth() / 2, modo.getHeight() / 2);
device.setFullScreenWindow(null);
mainWindow.setCursor(Cursor.DEFAULT_CURSOR);
mainWindow.setVisible(true);
mainWindow.repaint();
}
if (isPlaying) {
mainWindow.mediaPlayer.start();
}
}
您只需在设置FullScreen时停止播放器。