相关疑难解决方法(0)

Swing - 更新标签

我有一个消息标签和一个提交按钮.将多次按下提交按钮,每次按下的操作最多可能需要一分钟.

按下按钮时,我想将消息设置为空,在任务完成后,我想将消息设置为"完成".

private void submitActionPerformed(java.awt.event.ActionEvent evt) {
   message = "";
   updateMessageLabel();

   doTheTask();

   /* this update is apply to the label after completion */
   message = "Complete";
}
Run Code Online (Sandbox Code Playgroud)

是否可以在submitActionPerformed()方法运行之前(或在方法中)更新该消息标签,但是在单击按钮之后?

java concurrency swing event-dispatch-thread

8
推荐指数
2
解决办法
1万
查看次数

使用Java实现工作站锁监听器

当我们同时按下 WIN_HOME+L 键时,窗口被锁定。我们可以找到很多在 VB 中监听窗口锁定事件的好例子。但我正在为 Java 做窗口锁定侦听器。我做了一些研究并制作了一个侦听窗口锁定事件的侦听器程序。它有两个界面和一个带有JFrame的主程序,并使用JNA库。

WindowUser32.java

public interface WindowUser32 extends User32
{   public static final WindowUser32 MYINSTANCE = (WindowUser32) Native.loadLibrary("user32",  WindowUser32.class, W32APIOptions.UNICODE_OPTIONS);
public int SetWindowLong(WinDef.HWND hWnd, int nIndex, Callback callback);
}
Run Code Online (Sandbox Code Playgroud)

窗口监听器.java

public interface WindowListener extends StdCallCallback
{
public LRESULT callback(HWND hWnd, int uMsg, WPARAM uParam, LPARAM lParam);
}
Run Code Online (Sandbox Code Playgroud)

和主类LockListener.java

public class LockListener
{

public static void main(String[] args)
    {   
        JFrame frame = new JFrame();
    frame.setVisible(true);

    HWND hwnd = new HWND();
    hwnd.setPointer(Native.getWindowPointer(frame));

    Wtsapi32.INSTANCE.WTSRegisterSessionNotification(hwnd, Wtsapi32.NOTIFY_FOR_ALL_SESSIONS);

    WindowListener listener = new …
Run Code Online (Sandbox Code Playgroud)

java swing jna

3
推荐指数
1
解决办法
2581
查看次数

在下载过程中使用swingworker更新JProgressBar

问题已解决!!!!!! 非常感谢trashgod和HoverCraftFullOfEels!我终于通过使用下面的例子并略微改变它来获得这个概念.更改允许缩放进度条(默认为100个单位).再次感谢您的耐心和愿意为此而努力.意味着很多人,~Kyte

ps - + 1全部'围绕:)

/** @see http://stackoverflow.com/questions/4637215 */
public class Threading_01 extends JFrame {

private static final String s = "0.00";
private JProgressBar progressBar = new JProgressBar(0, 100);
private JLabel label = new JLabel(s, JLabel.CENTER);

public Threading_01() {
    this.setLayout(new GridLayout(0, 1));
    this.setTitle("?2");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.add(progressBar);
    this.add(label);
    this.setSize(161, 100);
    this.setLocationRelativeTo(null);
    this.setVisible(true);
}

public void runCalc() {
//    progressBar.setIndeterminate(true);
    TwoWorker task = new TwoWorker();
    task.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            if ("progress".equals(e.getPropertyName())) {
                progressBar.setIndeterminate(false);
                progressBar.setValue((Integer) e.getNewValue());
                System.out.println("**: " …
Run Code Online (Sandbox Code Playgroud)

java swing multithreading swingworker jprogressbar

2
推荐指数
1
解决办法
4660
查看次数

JDialog没有出现

该程序大多数工作正常,但不打开任何窗口.它应该在桌面右下方显示一个小对话框.但是对于另一个人来说,编译相同的代码没有问题.我们有相同的Java运行时(1.8_u40).我怎样才能解决这个问题?

我把代码放在下面:

import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.RoundRectangle2D;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class ProgressDialog {
    private JDialog dialogFrame;
    private JProgressBar progressBar;
    private JLabel headingLabel;
    private Uploader callerUploader;

    public ProgressDialog() {

        dialogFrame = new JDialog();
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | UnsupportedLookAndFeelException ex) {
            System.err.println(ex.toString());
        }

        dialogFrame.setSize(200, 50);
        dialogFrame.setLayout(new GridBagLayout());

        GridBagConstraints constraints = new GridBagConstraints(); …
Run Code Online (Sandbox Code Playgroud)

java swing awt jdialog java-8

2
推荐指数
1
解决办法
467
查看次数

背景SwingWorker线程不执行特定的代码段

我找不到更好的方式在问题的标题中表达问题,但希望你能理解......

我有以下代码......

[...]
final JDialog waitingDialog = optionPane.createDialog(optionPane, "Processing in backgroung");

waitingDialog.setLocationRelativeTo(homeFrame);
waitingDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);


SwingWorker<Void, Void> backgroundThread = new SwingWorker<Void, Void>() {

    @Override
    protected Void doInBackground() throws Exception {
        // Background processing is done here
        System.out.println("[DEBUG] -- Background processing has started");
        MyCustomClass.initParameters();
        System.out.println("DEBUG] -- initParameters() has finished. Starting main processing now...");
        waitingDialog.setVisible(true);
        MyCustomClass.run();
        return null;
    }

    // This is called when background thread above has completed
    @Override
    protected void done() {
        waitingDialog.dispose();
    };
};
backgroundThread.execute();

[and does other things after this...] …
Run Code Online (Sandbox Code Playgroud)

java debugging swing multithreading swingworker

1
推荐指数
1
解决办法
1552
查看次数

Java - JProgress栏没有显示(线程)

我正在为程序添加一个功能,以将一些内容保存到文件中.进度条(在其自己的JFrame中)显示进度,但进度条仅显示在它读取的最后一个值上.我有一个由主线程更新的全局,表示已完成工作的百分比,另一个线程读取此全局并相应地更新进度条.现在,当它运行时,JFrame为空,然后活动完成,然后进度条显示自己的完整数量.如何让它随着时间的推移更新进度(并从头开始显示JProgressbar)?这是我的代码:

public class GenomeAnnotator{
    private JProgressBar csvProgressBar;
    private JFrame csvSaveLoadFrame;     //for the progress bar
    private Container csvCon;
    private double csvPercentSaved;  //% of work completed

    public JFrame m_frame;    //main program frame


....



public static void main(String[] args){
    ...
    showGUI();
    ...
}

public void showGUI(){
   ...

   JMenu file = new JMenu("File");
   JMenu exptann = new JMenu("Export annotation..);
   JMenuItem exptcsv = newJMenuItem("CSV format");
   exptcsv.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {

          ..determine output file + checks...

          System.out.println("Writing to .csv file......"); 

          csvSaveLoadFrame = …
Run Code Online (Sandbox Code Playgroud)

java swing multithreading jprogressbar

1
推荐指数
1
解决办法
148
查看次数