JFileChooser显示外部全屏显示的JFrame [英] JFileChooser showing outside Full screened JFrame
问题描述
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Sample {
public static String audioName;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setTitle("Frame");
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
device.setFullScreenWindow(frame);
device.setDisplayMode(new DisplayMode(800, 600, 32, 60));
frame.setVisible(true);
JButton btn = new JButton();
btn.setText("Button");
JPanel panel = new JPanel();
panel.add(btn);
frame.add(panel);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
int returnName = chooser.showOpenDialog(frame);
if (returnName == JFileChooser.APPROVE_OPTION) {
System.out.println("Sample");
}
}
});
}
}
如何在全屏显示JFileChooser?我不熟悉JInternalFrame/JDesktopPane,您认为这可以解决此问题,还是有另一种方法可以解决此问题?
How can I show the JFileChooser inside my full screen? I'm not familiar with JInternalFrame/JDesktopPane, do you think that will fix this problem or is there another method of doing this?
推荐答案
在装有Java 6的Windows XP计算机上,JFileChooser
在框的中央.
The JFileChooser
is in the center of the frame for me on a Windows XP computer with Java 6. I moved the frame to various places on my two displays.
我注释掉了更改显示设置的行,并修复了其他一些问题.
I commented out the lines that change the display settings, and fixed a few other problems.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class Sample implements Runnable {
public static String audioName;
public void run() {
final JFrame frame = new JFrame();
frame.setTitle("Frame");
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// GraphicsDevice device = GraphicsEnvironment
// .getLocalGraphicsEnvironment().getDefaultScreenDevice();
// device.setFullScreenWindow(frame);
// device.setDisplayMode(new DisplayMode(800, 600, 32, 60));
JButton btn = new JButton();
btn.setText("Button");
JPanel panel = new JPanel();
panel.add(btn);
frame.add(panel);
frame.setExtendedState(
frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
int returnName = chooser.showOpenDialog(frame);
if (returnName == JFileChooser.APPROVE_OPTION) {
System.out.println("Sample");
}
}
});
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Sample());
}
}
如果要最大化JFrame
,请在setVisible
方法之前的某处添加以下语句.
If you want to maximize your JFrame
, you add the following statement somewhere before your setVisible
method.
frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
这篇关于JFileChooser显示外部全屏显示的JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!