1

if i directly use vlcj to show full screen then it's ok,but when i initially set a fixed size and later on the fly set it to full screen then it losts it's rendering, code:


    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);

but if i use a process when press "enter" it will be full screen then it fails

        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);
}
4

2 回答 2

1

I apply the following method in my code to toggle full-screen in 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);
}

Usage:

decorated = !decorated;
toggleDecoration(decorated);
于 2012-08-07T01:57:44.777 回答
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();
		}
	}

您只需要在设置全屏时停止播放器。

于 2014-10-13T00:41:30.013 回答