如果你在Swing中打开一个对话框,比如一个JFileChooser,它就像这个伪代码:
swing event thread { create dialog add listener to dialog close event { returnValue = somethingFromDialog } show dialog (wait until it is closed) return returnValue }
我的问题是:这怎么可能有效?如您所见,线程等待返回,直到对话框关闭.这意味着Swing事件线程被阻止.然而,人们可以与对话框进行交互,AFAIK需要该对话框才能运行.
那怎么办?
不幸的是,看起来这个最近封闭的问题还不太清楚.这是典型的输出:
run:
Trying to Remove JDialog
Remove Cycle Done :-)
Checking if still exists any of TopLayoutContainers
JFrame
JDialog
Will Try Remove Dialog again, CycleNo. 1
-----------------------------------------------------------
Trying to Remove JDialog
Remove Cycle Done :-)
Checking if still exists any of TopLayoutContainers
JFrame
JDialog
Will Try Remove Dialog again, CycleNo. 2
-----------------------------------------------------------
Trying to Remove JDialog
Remove Cycle Done :-)
Checking if still exists any of TopLayoutContainers
JFrame
JDialog
Will Try Remove Dialog again, CycleNo. 3
-----------------------------------------------------------
Trying …
Run Code Online (Sandbox Code Playgroud) 我需要从a中删除最大化和最小化按钮JFrame
.请建议如何做到这一点.
我已经制作了自己的SwingWorker示例,以熟悉它的工作原理.
我想要做的是以下内容:当单击按钮时,我想要一个进度条出现,直到任务完成我想简单地删除进度条并在对话框中添加一个字符串.
单击该按钮时,进度条会出现,但永远不会消失.(10秒后永远不会删除进度条,永远不会放置标签)
这是一个SSCCE:
package swingtesting;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.SwingWorker;
public class SwingTesting {
/**
* Creates a frame that will hold a simple button to make use of SwingWorker
*/
public static void main(String[] args) {
// TODO code application logic here
JFrame frame = new JFrame();
JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new GuiWorker().execute();
}
});
button.setText("Test Me");
frame.getContentPane().add(button); …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个像这个页面中的对话框:
http://jqueryui.com/demos/dialog/#modal-confirmation
(点击查看源代码)
在底部是放置在对话框中的div.当javascript调用时,该对话框工作正常,但加载时页面底部的对话框显而易见.(减去javascript函数调用时应用的所有样式)
如何隐藏div并仍允许对话框使用它?我已经尝试设置style ="visibility:hidden"但是这会阻止它在被javascript调用时显示.
有人可以显示简单的Java Swing代码/ Web资源,当点击JFrame的按钮时,它会将弹出对话框定位在现有JFrame窗口的顶部吗?
我无法将框架设置为对话框的所有者.通常当我扩展JDialog
类来创建对话框时,我会super(frame)
用来指定对话框的所有者,这样当你按下它们时它们都不会脱节alt+tab
.但是当我使用new
like 创建对话框时,我JDialog dialog = new JDialog()
无法将框架指定为对话框的所有者.
以下示例演示了以上两种方法.Top Click
按钮打开一个没有扩展JDialog的对话框.Bottom Click
按钮打开一个扩展JDialog的对话框.
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class DialogEx {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
new DialogEx().createUI();
}
};
EventQueue.invokeLater(r);
}
private void createUI() {
final JFrame frame = new JFrame();
frame.setLayout(new …
Run Code Online (Sandbox Code Playgroud) 我有一个模态设置对话框,这是一个JDialog.在这个设置窗口中,我将一些组件(包括按钮)放到另一个模态设置对话框中,该对话框也是JDialog.我把它们变成了JDialogs,因为这是我所知道的唯一一种模态对话框.
问题是这样的:当我创建主设置对话框时,我必须构建JDialog,或者没有父框架或父框架.由于我的主窗口是JFrame,我可以将其传递给主设置对话框构造函数.但是当我想创建第二个模态设置对话框时,它应该将主设置对话框作为父对象,我找不到获取JDialog的(J)框架的方法.我确实希望将该主要设置对话框作为父对象传递,以便第二个设置对话框在显示时以中心为中心.让我们假设第二个设置对话框没有用于传递位置的构造函数,只是JDialog的构造函数.
有没有办法获得JDialog的(J)框架?我的设置中是否存在设计缺陷,我是否应该使用其他设置对话框?(如果是这样,我应该如何设置这些替代设置对话框?)
谢谢你的帮助,Erik
更新:谢谢大家的答案.他们让我明白,显然并不是绝对有必要拥有JDialog的所有者.我认为对话框需要能够禁用所有者,直到对话框关闭,但显然模态独立于所有者.我还注意到即使对于所有者,对话框仍然不以所有者为中心,所以现在我的代码如下:
public class CustomDialog extends JDialog {
public CustomDialog(String title) {
setModal(true);
setResizable(false);
setTitle(title);
buildGUI();
}
public Result showDialog(Window parent) {
setLocationRelativeTo(parent);
setVisible(true);
return getResult();
}
}
Run Code Online (Sandbox Code Playgroud)
这也允许模态对话框中的模态对话框.
感谢你的帮助!
我目前正在使用此代码创建JDialog;
package com.kamuara.reposync.window;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
public class SheetDialog {
private JFrame _windowFrame;
public static void main(String[] args) {
System.setProperty("apple.awt.documentModalSheet", "true");
System.setProperty("apple.awt.brushMetalLook", "true");
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
new SheetDialog();
} catch (Exception e) {
e.printStackTrace();
}
}
public SheetDialog() {
_windowFrame = new JFrame();
_windowFrame.setResizable(false);
_windowFrame.setBounds(100, 100, 451, 320);
_windowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_windowFrame.getContentPane().setLayout(null);
_windowFrame.setVisible(true);
JButton showDialogButton = new JButton("Show Dialog");
showDialogButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) …
Run Code Online (Sandbox Code Playgroud) 您可以创建一个Java Swing JDialog
框(或替代Swing对象类型),我可以使用它来提醒用户某个事件,然后在延迟后自动关闭对话框; 无不必关闭对话的用户?
jdialog ×10
java ×9
swing ×9
jframe ×2
modal-dialog ×2
css ×1
jfilechooser ×1
jquery ×1
macos ×1
runtime ×1
scheduler ×1
swingworker ×1
timer ×1