Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [Update GUI] thread separato

    Ciao ho un JFrame che esegue alcune operazioni decisamente pesanti.
    Cosa ho pensato? DI usare un bel thread separato.
    In questo thread eseguo l' operazione, ma prima, lancio una GUI di attesa con un prograssBar undetermineted.

    codice:
    	private void btnAllineaMouseClicked(MouseEvent e) {
    		video.Waiter wait = new video.Waiter();
    		wait.setVisible(true);
    		SwingUtilities.invokeLater(new Runnable(){
    			public void run(){
    				updateIndenn();
    			}
    		});
    		wait.dispose();
    	}
    Il problema è che mi si apre la finestra wait in Pole Position, ma resta Grigia, la JVM non renderizza correttamente i controlli. Cosa devo usare, 2 thread, 1 per l' operazione ed uno per la JFrame di attesa? ... ...

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: [Update GUI] thread separato

    Originariamente inviato da raffaeu
    Ciao ho un JFrame che esegue alcune operazioni decisamente pesanti.
    Cosa ho pensato? DI usare un bel thread separato.
    In questo thread eseguo l' operazione, ma prima, lancio una GUI di attesa con un prograssBar undetermineted.

    codice:
    	private void btnAllineaMouseClicked(MouseEvent e) {
    		video.Waiter wait = new video.Waiter();
    		wait.setVisible(true);
    		SwingUtilities.invokeLater(new Runnable(){
    			public void run(){
    				updateIndenn();
    			}
    		});
    		wait.dispose();
    	}
    Io qui non vedo alcun thread. C'è un Runnable il cui compito è eseguire updateIndenn(). Però questo Runnable viene eseguito dopo che btnAllineaMouseClicked() ha terminato.
    In pratica il metodo btnAllineaMouseClicked() termina praticamente subito e updateIndenn() viene eseguito successivamente nel contesto del thread di Swing (event-dispatch thread).
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    Ok in pratica dovrei gestire questa Widget di attesa nella routine updateIndenn e non nell Runnable?
    Allora non ho ben capito la logica di Runnable ...

    ops ...


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.