- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
**你好,我正在尝试用 java 创建一个存档器。这意味着我不断地从流中读取和写入。我希望能够更新 JProgressBar 以显示我已经写了多少。我的代码当前在存档中的每个条目之后更新进度栏。我的变量和所有内容都表明代码已更新,但它没有显示在屏幕上。每次进入存档后,我都会在包含进度条和文本的 JPanel 上调用 revalidate() 方法,但屏幕上没有任何反应。在写入存档的输出流完全完成写入之前,屏幕不会更新。然后,我看到完整的进度条,进度文本中显示“已写入 24 个文件中的 24 个”。
谁能告诉我如何在代码执行完毕之前更新图形?谢谢
这是我的代码:
WritingBox.java:
package org.apache.commons.compress;
import javax.swing.JDialog;
public class WritingBox extends javax.swing.JDialog {
/** Creates new form WritingBox */
public WritingBox(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
theprogressbar.setMaximum(1);
theprogressbar.setMinimum(0);
this.setLocation(parent.getLocationOnScreen().x+(parent.getWidth()-this.getWidth())/2, parent.getLocationOnScreen().y+(parent.getHeight()-this.getHeight())/2);
this.setVisible(true);
}
public void progressListener(Progress p) {
writtenxoutofx.setText("Written "+Integer.toString(p.doneSoFar)+" out of "+Integer.toString(p.total)+" files to the Archive");
theprogressbar.setValue(p.doneSoFar/p.total);
if (p.doneSoFar == p.total) this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
thecontainer.revalidate();
};
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
thecontainer = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
writtenxoutofx = new javax.swing.JLabel();
theprogressbar = new javax.swing.JProgressBar();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setName("Form"); // NOI18N
thecontainer.setName("thecontainer"); // NOI18N
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(targzipmanager.TarGzipManagerApp.class).getContext().getResourceMap(WritingBox.class);
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
writtenxoutofx.setText(resourceMap.getString("writtenxoutofx.text")); // NOI18N
writtenxoutofx.setName("writtenxoutofx"); // NOI18N
theprogressbar.setName("theprogressbar"); // NOI18N
javax.swing.GroupLayout thecontainerLayout = new javax.swing.GroupLayout(thecontainer);
thecontainer.setLayout(thecontainerLayout);
thecontainerLayout.setHorizontalGroup(
thecontainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(thecontainerLayout.createSequentialGroup()
.addContainerGap()
.addGroup(thecontainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(theprogressbar, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
.addComponent(jLabel1)
.addComponent(writtenxoutofx))
.addContainerGap())
);
thecontainerLayout.setVerticalGroup(
thecontainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(thecontainerLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(writtenxoutofx)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(theprogressbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(thecontainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(thecontainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel thecontainer;
private javax.swing.JProgressBar theprogressbar;
private javax.swing.JLabel writtenxoutofx;
// End of variables declaration
}
进度.java
package org.apache.commons.compress;
public class Progress { //This is basically a Struct
public int total;
public int doneSoFar;
private Progress (){
}
public Progress(int d, int t){
total = t;
doneSoFar = t;
}
}
TarArchive.java:doSave 方法
public void doSave(OutputStream output) throws ArchiveException {
// Stream initializing
//BufferedInputStream origin = null;
//out.setMethod(ZipOutputStream.DEFLATED);
//byte data[] = new byte[BUFFER];
// get a list of files from current directory
// less than one file leads to an exception
Iterator iterator = this.getEntryIterator();
if(!iterator.hasNext()) {
throw new ArchiveException("There must be at least one file to be pack.");
}
JFrame jf = targzipmanager.TarGzipManagerApp.getApplication().getMainFrame();
WritingBox wb = new WritingBox(jf, false);
TarOutputStream out = null;
int x = 0;
try {
out = new TarOutputStream(new BufferedOutputStream(output));
while(iterator.hasNext()) {
x++;
ArchiveEntry archiveEntry = (ArchiveEntry)iterator.next();
InputStream fInputStream = archiveEntry.getStream();
TarEntry entry = new TarEntry(archiveEntry.getName());
entry.setModTime( 0 );
entry.setSize( fInputStream.available() );
entry.setUserID( 0 );
entry.setGroupID( 0 );
entry.setUserName( "avalon" );
entry.setGroupName( "excalibur" );
entry.setMode( 0100000 );
out.putNextEntry( entry );
out.copyEntryContents( fInputStream );
out.closeEntry();
wb.progressListener(new Progress(x, entries.size()));
}
} catch (IOException e) {
throw new ArchiveException("Creation of this archive failed cause of IOExceptions.", e);
} finally {
try {
out.close();
} catch (IOException e1) {
throw new ArchiveException("Creation of this archive failed cause of IOExceptions.", e1);
}
}
}
有人可以帮助我吗?即使我在每次输入后调用 revalidate(),它也只会在代码停止并开始等待时更新。 **
最佳答案
听起来您正在 AWT 事件调度线程 (EDT) 上执行文件 I/O。这会阻止任何重画或事件处理。在不同的线程上运行 I/O,并通过 java.awt.EventQueue.invokeLater 更新 GUI。
关于java - JComponent.revalidate() 在代码完成之前不会更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3410127/
在我的理解中,这两个指令都意味着缓存服务器将要求原始服务器重新验证来自客户端浏览器的请求。这两个指令有什么区别? 最佳答案 RFC 7234, section 5.2.2.7 , 解释: The "p
Cache-Control: no-cache 与 Cache-Control: max-age=0, must-revalidate, proxy-revalidate 的 HTTP 响应有什么区别
我经常用 Cache-Control: no-cache 或 Cache-Control: max-age=0 规范说must-revalidate是为了max-stale...(服务器问题max-s
因此,我编写了一段代码,在单击框架南部区域的按钮后,您会得到一个矩形。 但是由于这个原因,单击按钮后代码似乎不起作用 public void actionPerformed(ActionEvent e
我有一个主 JPanel、一个内部 JPanel 和一个用于内部 JPanel 的 JScrollPane mainPanel = new JPanel(); innerPanel = new JPa
我就遇到过这样的问题。当我在容器上调用 .revalidate 时,出现 IndexOutOfBoundsException。 我有一个 Runnable 类,它可以增加或减少组件的边距。我用它来制作
我正在尝试创建一个窗口框架来显示游戏窗口。我在 GameWindow 类中扩展了 JFrame 并创建了两个方法:drawBackground(用实心矩形填充屏幕)和 drawGrid,使用 for
**你好,我正在尝试用 java 创建一个存档器。这意味着我不断地从流中读取和写入。我希望能够更新 JProgressBar 以显示我已经写了多少。我的代码当前在存档中的每个条目之后更新进度栏。我的变
对于我的程序,我有一个 JPane,随着游戏的进行,它会向面板添加标签,但是我可以让面板显示的唯一方法是使用 add(label) 然后重新验证,反之亦然以删除标签。 我的问题是,一旦我在屏幕上有超过
我们正在使用Varnish缓存6.2来位于WebAPI后端的前面。 后端会在某些请求上向后发送一个缓存控制 header ,以便我们可以缓存更长的时间。 但是-如果后端出现故障并保持故障状态,我们将在
我正在尝试使Varnish与最后修改的 header 一起使用,但是无论我做什么,我的页面都会在120年代被缓存,并且Varnish永远不会使用后端进行验证。 我的后端正在发送这些 header :
我有这个 NextJS 站点,其中有从 Firestore 加载数据的 getStaticProps。 我有这个: return { props: { allPosts: post
我对java很陌生,我正在尝试创建我自己的拼字游戏。我创建了自己的 Board 类和 Tile 类 JPanel。当我在板上绘制图 block 时: Tile tile = new Tile(curr
Cloudflare 记录了 Cache-Control 的指令列表 header ,包括 stale-while-revalidate . stale-while-revalidate= When
网址:http://tinyurl.com/358lh6a 每当 DomainSelect(域扩展名)无论如何更改时,我都想重新验证宫殿地址(他们想要的域,形式是:名称)。 我尝试了一个简单的方法:
我在 JPanel 中有一个方法 private void paintScore(Graphics2D g) { Font scoreFont = new Font("Arial", Font
我正在组合一个 Swing 应用程序,我经常想在其中替换 JPanel 的内容。为此,我调用 removeAll(),然后添加我的新内容,然后调用 revalidate()。 但是,我发现旧内容实际上
本文整理了Java中org.knowm.xchart.XChartPanel.revalidate()方法的一些代码示例,展示了XChartPanel.revalidate()的具体用法。这些代码示例
如果应用中的购买调用 BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED:需要调用 acknowledgePurchase(... 重新验证订单的
我在尝试查询表 AVC 时突然开始遇到此错误。 ORA-04045: errors during recompilation/revalidation of PUBLIC.AVC ORA-04098:
我是一名优秀的程序员,十分优秀!