有没有办法从ProgressMonitor模式进行对话?
编辑:
JAVA API中的ProgressMonitor类将带来一个顶部但不是Modal的对话框.用户仍然可以访问后台GUI.我正在寻找一个模态对话框来显示进度,并允许用户在中间停止任务.
有没有办法设置相对于JFrame?的对话框位置?
我想将对话框置于包含GUI的框架中,而对话框通常出现在屏幕的中心而不是GUI中.
我原来问的并没有明确说明我的问题/问题,所以我会更好地解释.我有一个JButton,设置一个JDialog可见.JDialog将WindowListener其设置为在windowDeactivated()事件中不可见,该事件在用户在对话框外单击时触发.按钮ActionListener检查对话框是否为可见,如果为true则隐藏它,如果为false则显示该对话框.
windowDeactivated()只要用户在对话框外单击,就会始终触发是否单击按钮.我遇到的问题是当用户单击按钮关闭对话框时.该对话框由关闭WindowListener,然后ActionListener尝试显示它.
如果windowDeactivated()没有setVisible(false),则对话框仍然打开,但在父窗口后面.我要求的是如何访问里面的点击位置windowDeactivated().如果我知道用户点击了按钮并且windowDeactivated()可以跳过隐藏对话框,那么按钮ActionListener会看到它仍然可见并隐藏它.
public PropertiesButton extends JButton {
private JDialog theWindow;
public PropertiesButton() {
theWindow = new JDialog();
theWindow.setUndecorated(true);
theWindow.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
theWindow.add(new JMenuCheckBoxItem("Something"));
theWindow.addWindowListener(new WindowListener() {
// just an example, need to implement other methods
public void windowDeactivated(WindowEvent e) {
theWindow.setVisible(false);
}
});
this.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (theWindow.isVisible()) {
theWindow.setVisible(false);
} else { … 我想在显示对话框时禁用单击背景面板或框架.我希望对话框不断显示在此面板或框架的顶部,直到它关闭.

我怎样才能做到这一点?
在JFileChooser的Windows外观中,JFileChooser对话框的左侧显示五个按钮:Recent Items,Desktop,My Documents,Computer和Network.这些都表示文件系统的视图,因为Windows资源管理器会显示它们.看起来除非调用setSelectedFile()或setCurrentDirectory()方法,否则JFileChooser默认为My Documents视图.
我试图让用户轻松选择多个映射网络驱动器中的一个,这应该出现在"计算机"视图中.有没有办法将JFileChooser设置为默认打开"计算机"视图?
我尝试了几种方法来强制它,最近的方法是找到根目录并将其设置为currentDirectory,但这显示了该根节点的内容.最新的代码包含在下面.
private File originalServerRoot;
private class SelectOriginalUnitServerDriveListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
JFileChooser origDriveChooser = new JFileChooser();
origDriveChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
File startFile = new File(System.getProperty("user.dir")); //Get the current directory
// Find System Root
while (!FileSystemView.getFileSystemView().isFileSystemRoot(startFile))
{
startFile = startFile.getParentFile();
}
origDriveChooser.setCurrentDirectory(startFile);
origDriveChooser.setDialogTitle("Select the Mapped Network Drive");
int origDriveChooserRetVal = origDriveChooser.showDialog(contentPane,"Open");
if (origDriveChooserRetVal == JFileChooser.APPROVE_OPTION)
{
originalUnitServerRoot = origDriveChooser.getSelectedFile();
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否有一种方法允许我默认选择"计算机"视图(或网络,或任何其他视图),或任何方式欺骗JFileChooser?
编辑
感谢您快速彻底的答案.我结合了Hovercraft Full Of Eels和Guillaume Polet的答案,尝试使代码适用于任何驱动器号.结果代码如下.再一次,谢谢.
private File originalServerRoot;
private class …Run Code Online (Sandbox Code Playgroud) 有没有办法如何在Swing中使用一个禁止任何gui活动的对话框,但同时又不停止在设置为可见的线程上执行?
我有一个JDialog从用户那里得到一个名字.在后面JDialog,是一个小程序.我不希望用户在输入名称之前访问该applet.我试过了JDialog.setAlwaysOnTop(true),但applet抛出了一个AccessException错误.所以我所做的是保持一个while循环,JDialog.setVisible(true)直到JtextField(用户名输入)为空("").但由于某些原因,这个工作真的很慢,意味着JDialog 负载,但是需要时间来关注JTextField,甚至当用户输入他的名字时,它变得非常慢......就像2秒内的一个角色......还有其他吗?在访问applet之前强制用户输入名称的方法?
我有一个非常大的应用程序,它有多个对话框.我的任务是确保一个不完全可见的对话框(因为用户将其从可见屏幕区域拉出)被移回屏幕中心.
当我只处理一个屏幕时,这没问题.它工作得很好......但是,这个应用程序的大多数用户在他们的桌面上有两个屏幕...
当我试图弄清楚对话框显示在哪个屏幕上并将其置于该特定屏幕上时,......好吧,它实际上是中心,但是在主屏幕上(可能不是屏幕上显示对话框).
为了向您展示我到目前为止的想法,这里的代码是......
/**
* Get the number of the screen the dialog is shown on ...
*/
private static int getActiveScreen(JDialog jd) {
int screenId = 1;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gd = ge.getScreenDevices();
for (int i = 0; i < gd.length; i++) {
GraphicsConfiguration gc = gd[i].getDefaultConfiguration();
Rectangle r = gc.getBounds();
if (r.contains(jd.getLocation())) {
screenId = i + 1;
}
}
return screenId;
}
/**
* Get the Dimension of the screen with the given id …Run Code Online (Sandbox Code Playgroud) 我正在为我的笔记本电脑开发一个工具.我想在JFrame中禁用最小化按钮.我已经禁用了最大化和关闭按钮.
以下是禁用最大化和关闭按钮的代码:
JFrame frame = new JFrame();
frame.setResizable(false); //Disable the Resize Button
// Disable the Close button
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
Run Code Online (Sandbox Code Playgroud)
请告诉我如何禁用最小化按钮.
我有一个关于未修饰的边界JDialog使用的问题Metal L&F.
看看这张图片,看看这个窗口上的边框:

我试图弄清楚如何摆脱或改变围绕外面的蓝色边框的颜色JDialog.我查看了UI的默认设置,Look & Feel但我无法想出任何有用的功能.
有没有人对如何摆脱这个边界有任何想法?
谢谢!
java ×10
jdialog ×10
swing ×9
jframe ×3
border ×1
center ×1
concurrency ×1
jbutton ×1
jfilechooser ×1
jpanel ×1
jpopupmenu ×1
jprogressbar ×1
jwindow ×1
modal-dialog ×1
uimanager ×1
visibility ×1
windows ×1