java Swing全屏显示问题

hehe264 2011-08-01 08:59:00
我用
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
gd.setFullScreenWindow(frame);
来实现界面全屏显示,全屏没问题,但是全屏退出时出现了问题,通过采用gd.setFullScreenWindow(null);来实现退出,但是发现界面没有window的最大最小化、关闭状态栏。
请问如何能在退出全屏时能够有window的最大最小化、关闭状态栏。
...全文
909 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
oppo 2011-08-08
  • 打赏
  • 举报
回复
灌水,不懂。。。
hehe264 2011-08-08
  • 打赏
  • 举报
回复
up,up,up~~~~
hehe264 2011-08-08
  • 打赏
  • 举报
回复
up,贴上全部代码。
//=====================================================================
package com.cc502.net;

import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.Toolkit;
import javax.swing.WindowConstants;
import java.awt.Dimension;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Label;
import javax.swing.ImageIcon;
import java.awt.Graphics;
import javax.swing.JLabel;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GraphicsEnvironment;
import java.awt.GraphicsDevice;
import java.awt.HeadlessException;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.Font;
import java.util.Locale;
import java.awt.DisplayMode;
import java.awt.Window;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
import javax.swing.AbstractAction;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowListener;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2010</p>
*
* <p>Company: kthw.ltd</p>
*
* @author shenxian
* @version 1.0
*/
public class SplitJPane extends JFrame {
private GraphicsDevice device;
/**
* 返回当前window
*/
public Window getFullScreen() {
return device.getFullScreenWindow();
}

/**
* 退出全屏独占模式
*/
public void restoreScreen() {
frame.getGraphicsConfiguration().getDevice().setFullScreenWindow(null);
}
/**
* 设置全屏独占模式 ,该方法可以将window设置为全屏模式
*/
public void setFullScreen(DisplayMode displayMode, JFrame window) {
window.setUndecorated(true); //取消window装饰
window.setResizable(false);
device.setFullScreenWindow(window);
if (displayMode != null && device.isDisplayChangeSupported()) {
device.setDisplayMode(displayMode);
}
}

public SplitJPane() {
device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

final String ImagePatg = "D:\\download\\images\\" ;
image1 = new ImageIcon(ImagePatg + "001.jpg");
image2 = new ImageIcon(ImagePatg + "002.jpg");
image3 = new ImageIcon(ImagePatg + "003.jpg");
image4 = new ImageIcon(ImagePatg + "004.jpg");
image5 = new ImageIcon(ImagePatg + "005.jpg");
image6 = new ImageIcon(ImagePatg + "006.jpg");
allPaneInfo = new JPanel(new GridLayout(3,3));
pane1 = new JPanel() {
public void paintComponent(Graphics g) {
// 图片随窗体大小而变化
g.drawImage(image1.getImage(), 0, 0, this.getSize().width,
this.getSize().height, this);
}
};
// label = new JLabel(){
// public void paintComponent(Graphics g) {
// // 图片随窗体大小而变化
// g.drawImage(image1.getImage(), 0, 0, this.getSize().width,
// this.getSize().height, this);
// }
// };
pane2 = new JPanel(new BorderLayout()){
public void paintComponent(Graphics g) {
g.drawImage(image2.getImage(), 0, 0, this.getSize().width,
this.getSize().height, this);
}
};
pane3 = new JPanel() {
public void paintComponent(Graphics g) {
g.drawImage(image3.getImage(), 0, 0, this.getSize().width,
this.getSize().height, this);
}
};
pane4 = new JPanel(){
public void paintComponent(Graphics g) {
g.drawImage(image4.getImage(), 0, 0, this.getSize().width,
this.getSize().height, this);
}
};
pane5 = new JPanel(){
public void paintComponent(Graphics g) {
g.drawImage(image5.getImage(), 0, 0, this.getSize().width,
this.getSize().height, this);
}
};
pane6 = new JPanel(){
public void paintComponent(Graphics g) {
g.drawImage(image6.getImage(), 0, 0, this.getSize().width,
this.getSize().height, this);
}

};
allPaneInfo.add(pane1);
//allPaneInfo.add(label);
allPaneInfo.add(pane2);
allPaneInfo.add(pane3);
allPaneInfo.add(pane4);
allPaneInfo.add(pane5);
allPaneInfo.add(pane6);
frame = new JFrame("分割Panel");
panelDes = new JPanel(new FlowLayout());
JLabel label = new JLabel("图片");
pre = new JButton("上一幅");
next = new JButton("下一幅");
panelDes.add(pre);
pre.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("前1幅");
image1 = new ImageIcon(ImagePatg + "201.jpg");
pane1 = null ;
pane1= new JPanel() {
public void paintComponent(Graphics g) {
// 图片随窗体大小而变化
g.drawImage(image1.getImage(), 0, 0,
this.getSize().width,
this.getSize().height, this);
}
};
frame.repaint();
}
});
allPaneInfo.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 4) {
restoreScreen();
}
}
});

panelDes.add(label);
panelDes.add(next);
frame.setUndecorated(true);
frame.getContentPane().add(allPaneInfo, BorderLayout.CENTER);
frame.getContentPane().add(panelDes, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setSize(800, 600);
//The following code ensure the window shown on the center of screen.
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((dim.width - frame.getWidth()) / 2, (dim.height - frame.getHeight()) / 2);
frame.getGraphicsConfiguration().getDevice().setFullScreenWindow(frame);
DisplayMode dm = new DisplayMode(dim.width,dim.height,DisplayMode.BIT_DEPTH_MULTI,DisplayMode.REFRESH_RATE_UNKNOWN);
this.setFullScreen(dm,frame);
frame.setVisible(true);


}
private JFrame frame = null;
private JButton pre = null, next = null;
private JLabel label = null ;
private JPanel pane1 = null;
private JPanel pane2 = null;
private JPanel pane3 = null;
private JPanel pane4 = null;
private JPanel pane5 = null;
private JPanel pane6 = null;
private JPanel allPaneInfo = null;
private JPanel panelDes = null ;
ImageIcon image1 = null ;
ImageIcon image2 = null ;
ImageIcon image3 = null ;
ImageIcon image4 = null ;
ImageIcon image5 = null ;
ImageIcon image6 = null ;
public static void main(String[] args) {

SplitJPane splitjpane = new SplitJPane();
}

}
//==================================================================
请大家看啥原因!
风尘中国 2011-08-06
  • 打赏
  • 举报
回复
上面说了,我用同样代码 在我那里退出了全屏之后是好好的,

不贴代码谁也解决不了,楼主保重

[Quote=引用 9 楼 hehe264 的回复:]

up,我问的是我退出全屏时用 gd.setFullScreenWindow(null);
但是没有window 边框,有办法解决没?
[/Quote]
Tobe 2011-08-06
  • 打赏
  • 举报
回复
杯具啊,呵呵,LZ这贴过几天再发吧,说不定刚好能碰到某些大神来巡贴就给解决了。
Codefans_Fan 2011-08-06
  • 打赏
  • 举报
回复
灌水了…有点不明白
huntor 2011-08-06
  • 打赏
  • 举报
回复
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
=>
frame.setExtendedState(JFrame.NORMAL);
hehe264 2011-08-05
  • 打赏
  • 举报
回复
up,我问的是我退出全屏时用 gd.setFullScreenWindow(null);
但是没有window 边框,有办法解决没?
wenjie4892543 2011-08-04
  • 打赏
  • 举报
回复
up!!
风尘中国 2011-08-04
  • 打赏
  • 举报
回复
单纯这两行代码发现不了问题,我用同样代码没有楼主的问题,希望将完整代码给出来,无关业务可以去掉

[Quote=引用 4 楼 hehe264 的回复:]

JFrame
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
gd.setFullScreenWindow(frame);
[/Quote]
hehe264 2011-08-03
  • 打赏
  • 举报
回复
JFrame
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
gd.setFullScreenWindow(frame);
风尘中国 2011-08-03
  • 打赏
  • 举报
回复
并不清楚你写的具体代码,我用这个方式是有最大化、最小化或还原这些按钮的,你可以把代码贴出来看看。
你是用的JFrame么还是JDialog什么的?
hehe264 2011-08-02
  • 打赏
  • 举报
回复
偌大个CSDN居然连个灌水的人都没!!!
hehe264 2011-08-01
  • 打赏
  • 举报
回复
怎么没得一个人回答捏。。。

67,516

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧