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,您认为这可以解决这个问题还是有其他方法可以做到这一点?
The JFileChooser
对于我来说,在装有 Java 6 的 Windows XP 计算机上,它位于框架的中心。我将框架移动到了两个显示器上的不同位置。
我注释掉了更改显示设置的行,并修复了一些其他问题。
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
method.
frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)