我有一个JDialg来显示某个任务的进度.要显示和隐藏对话框,我有以下方法,
public class ProgressDisplayer extends javax.swing.JDialog {
......
public void s_show() {
this.setTitle("Month End Status");
setModal(true);
setResizable(false);
pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public void s_hide() {
this.dispose();
}
...........
}
Run Code Online (Sandbox Code Playgroud)
当我尝试从线程中关闭这个JDialog框时,虽然它显示正常但我在调用pd.s_hide()方法时无法隐藏它.
...........
public void run() {
ProgressDisplayer pd = new ProgressDisplayer();
pd.s_show();
Thread.sleep(1000);
pd.s_hide();
}
.............
Run Code Online (Sandbox Code Playgroud)
请帮助我
我有一个gif动画图像,在jDialog中显示无限循环加载进度...但问题是当我加载这个jDialog时父框架代码停止.怎么做...这是我的代码..
ProgressDialouge pbDialog = new ProgressDialouge(this);
pbDialog.setVisible(true);
pbDialog.toFront();
postPairs.add(new BasicNameValuePair("PATH","authenticateUser.idoc"));
postPairs.add(new BasicNameValuePair("user_email",email));
postPairs.add(new BasicNameValuePair("user_password",password));
JSONArray jArray = asyncService.sendRequest(postPairs);
if(jArray != null){
new NewJFrame().setVisible(true);
this.setVisible(false);
}
Run Code Online (Sandbox Code Playgroud)
如果我改变我的JDiaog的ModalityType.MODELESS,它不会停止执行代码,但它也没有显示进度条..
我有一个使用JPA的项目J2SE.在一些JDialogs中,我会getResultList()在类的构造函数中返回并填充JTable,JComboBox,JList等.
因此,当我为这些对话框创建任何实例时,有时会很慢.
我认为使用SwingWorker和JProgressbar创建一个(加载)打开JDialogs是一个很好的解决方案,但我不知道该怎么做.
我正在尝试这个.
//
JProgressbar progress = new JProgressBar();
//custommer dialog
JDialog custommer = new JDialog(); //here slow because I have List<Customer> and others lists
custommer.setModal(true);
private void openDialogs(JDialog dialog){
progress.setVisible(true);
progress.setIndeterminate(true);
SwingWorker sw = new SwingWorker(){
protected Object doInBackground(){
//opening dialog
dialog.setVisible(true);
return null;
}
}
//after opened
protected void done(){
progress.setVisible(false);
}
}
Run Code Online (Sandbox Code Playgroud)
如何打开JDialog并创建一个用SwingWorker和JProgressbar打开的加载?
**我已根据我收到的帮助和评论更新了我的问题.现在我的问题是:在调用以下代码后:
SearchBox searchBox = new SearchBox(); // SearchBox extends JDialog
int state = searchBox.showSearchDialog(); // Sets visible to true and returns state
Run Code Online (Sandbox Code Playgroud)
我想让用户在searchBox(JDialog)中输入输入.因此,在searchBox.showSearchDialog()调用时基本上"停止"我的JFrame类(不应该这样做吗?它甚至不会setVisible(true)被调用).然后一旦用户在JDialog(searchBox类)中按下OK,"恢复"我的JFrame类并调用String query = searchBox.getQuery();.
我认为从searchBox.showSearchDialog()方法调用正弦setVisible(true)应该暂停,但事实并非如此.我的代码贯穿于:
seachBox = new SearchBox();
int state = seachBox.showSeachDialog();
String query = searchBox.getQuery();
Run Code Online (Sandbox Code Playgroud)
不停止.所以我的查询字符串回来都错了,因为在我的代码调用该方法之前,用户从未有机会输入任何内容.
JFrame 类:
import java.awt.Cursor;
Run Code Online (Sandbox Code Playgroud)
@SuppressWarnings("serial")公共类DataPersistance扩展JFrame {
private JPanel contentPane;
private JTable table;
private DataPersistanceController controller;
private DatabaseConnector dbConnector;
/**
* Launch the application.
*/
public static void main(String[] args)
{
// Sets the look …Run Code Online (Sandbox Code Playgroud) 我正在构建一个简单的程序.我有一个从JDialog扩展的类和从JFrame扩展的类,它是应用程序的GUI.我实现了ActionListener,它应该在单击JButton后打开对话框.没有任何事情发生,我无法弄清楚为什么.
GUI
package nemocnice_sam;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class App extends JFrame {
JTable tbl = new JTable();
JButton pridejPacienta = new JButton("P?idej pacienta");
JButton smazPacienta = new JButton("Smaž pacienta");
JButton export = new JButton("Export");
JButton konec = new JButton("Konec");
JPanel panel = new JPanel();
PacientDialog novyPacient;
ActionListener al = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == …Run Code Online (Sandbox Code Playgroud) 我有一个通常有效的设置,但我现在发现它有点痛苦.
我有一个JDialog(以前是一个JFrame,但我最近更改了UI流程以删除冗余JFrames)设置为BorderLayout,其中包含三个主要JPanels,标题,内容和页脚.
标题JPanel有一个正常加载的背景图像.但是,我正在调用setMinimumSize/ setPreferredSize/ etc的各种方式(我甚至试过setSize并且setBounds绝望了)并且JPanel没有正确调整大小.该组件的布局是BoxLayout,并且孩子们可以舒适地坐在其中,但这不应该影响我正在尝试使用标题面板本身.
唯一有效的方法是在父级上设置大小JDialog.但我不想这样做/从我所看到的看起来像是糟糕的设计.我还需要计算所有孩子的潜在宽度/高度,添加边距等.
建议我不是在寻找:"使用不同的LayoutManager."
我想了解是否有原因导致子组件不受尊重.
我可以提供代码,但是考虑到我正在处理的互锁系统的数量,隔离一个小的,可运行的段很困难.这是设置大小的相关代码段JPanel.图像尺寸为480*96.
public JPanelThemed(BufferedImage image) {
super();
this.backgroundImage = image;
setAllSimilarConstraints(new Dimension(image.getWidth(), image.getHeight()));
setOpaque(false);
}
// for use with BoxLayout as it requires explicit bounds to be set
public void setAllSimilarConstraints(Dimension dim) {
setPreferredSize(dim);
setMinimumSize(dim);
setMaximumSize(dim);
}
Run Code Online (Sandbox Code Playgroud) java ×6
jdialog ×6
swing ×6
animated-gif ×1
concurrency ×1
jbutton ×1
jframe ×1
jprogressbar ×1
listener ×1
swingworker ×1