gpt4 book ai didi

Java Swing Workers 和组合框问题

转载 作者:行者123 更新时间:2023-12-02 08:17:53 25 4
gpt4 key购买 nike

我正在使用 Swing 构建一个使用数据库的应用程序。我有一个奇怪的问题,我不知道如何解决。

在某个面板中,我有一个组合框,我想使用数据库查询来填充记录。完成构建包含组合框的 JPanel 后,我正在执行一个 Worker

private void populateLists(){
GetSimpleRecordsWorker worker = new GetSimpleRecordsWorker(Tables.characters,panelLeftDetails);
worker.execute();
}

doInBackground 执行 SELECT 查询,并在获取结果后 - 在 Worker 的 done() 方法中 - 更新面板的模型并调用面板的 refreshFromModel.

charI.setSimpleModel(simpleModel);
charI.refreshFromModel();

refreshFromModel 执行以下操作:

private void refreshFromSimpleModel(){
charSelectCombo.removeAllItems();
Pair[] pairs = simpleModel.getRecords();
for (int i=0; i<pairs.length; i++){
charSelectCombo.addItem(pairs[i]);
}
charSelectCombo.setSelectedItem(null);
}

现在的问题是,在完成refreshFromModel之后-GUI卡住/卡住。我不知道为什么!奇怪的是,在不同的框架中,我使用相同的方法 - 而且它的工作没有任何问题

此外,如果我尝试 removeAll 而不是 removeAllItems 它可以工作,但 ComboBox 会丢失箭头并表现得很奇怪。

我已经在调试器中获取了帧跟踪 - 诸如removeSourceEvent或Unsafe.park之类的东西都在那里。

 GUI.GuiHandler at localhost:53547 (Suspended)  
Daemon System Thread [Attach Listener] (Suspended)
Daemon System Thread [Signal Dispatcher] (Suspended)
Daemon System Thread [Finalizer] (Suspended)
Object.wait(long) line: not available [native method]
ReferenceQueue<T>.remove(long) line: not available
ReferenceQueue<T>.remove() line: not available
Finalizer$FinalizerThread.run() line: not available
Daemon System Thread [Reference Handler] (Suspended)
Object.wait(long) line: not available [native method]
Reference$Lock(Object).wait() line: 485
Reference$ReferenceHandler.run() line: not available
Thread [AWT-Shutdown] (Suspended)
Object.wait(long) line: not available [native method]
Object.wait() line: 485
AWTAutoShutdown.run() line: not available
Thread.run() line: not available
Daemon System Thread [Java2D Disposer] (Suspended)
Object.wait(long) line: not available [native method]
ReferenceQueue<T>.remove(long) line: not available
ReferenceQueue<T>.remove() line: not available
Disposer.run() line: not available
Thread.run() line: not available
Daemon Thread [AWT-Windows] (Suspended)
WToolkit.eventLoop() line: not available [native method]
WToolkit.run() line: not available
Thread.run() line: not available
Thread [AWT-EventQueue-0] (Suspended)
EventQueue.removeSourceEvents(Object, boolean) line: not available
WindowsComboBoxUI$WindowsComboBoxRenderer(Component).removeNotify() line: not available
WindowsComboBoxUI$WindowsComboBoxRenderer(Container).removeNotify() line: not available
WindowsComboBoxUI$WindowsComboBoxRenderer(JComponent).removeNotify() line: not available
CellRendererPane(Container).remove(int) line: not available
CellRendererPane(Container).remove(Component) line: not available
WindowsComboBoxUI(BasicComboBoxUI).getSizeForComponent(Component) line: not available
WindowsComboBoxUI(BasicComboBoxUI).getDisplaySize() line: not available
WindowsComboBoxUI(BasicComboBoxUI).getMinimumSize(JComponent) line: not available
AutoCompleteComboBox(JComponent).getMinimumSize() line: not available
FlowLayout.minimumLayoutSize(Container) line: not available
JPanel(Container).minimumSize() line: not available
JPanel(Container).getMinimumSize() line: not available
JPanel(JComponent).getMinimumSize() line: not available
BoxLayout.checkRequests() line: not available
BoxLayout.minimumLayoutSize(Container) line: not available
JPanel(Container).minimumSize() line: not available
JPanel(Container).getMinimumSize() line: not available
JPanel(JComponent).getMinimumSize() line: not available
BoxLayout.checkRequests() line: not available
BoxLayout.preferredLayoutSize(Container) line: not available
JPanel(Container).preferredSize() line: not available
JPanel(Container).getPreferredSize() line: not available
JPanel(JComponent).getPreferredSize() line: not available
BorderLayout.layoutContainer(Container) line: not available
JPanel(Container).layout() line: not available
JPanel(Container).doLayout() line: not available
JPanel(Container).validateTree() line: not available
JPanel(Container).validateTree() line: not available
JPanel(Container).validateTree() line: not available
JLayeredPane(Container).validateTree() line: not available
JRootPane(Container).validateTree() line: not available
JRootPane(Container).validate() line: not available
RepaintManager.validateInvalidComponents() line: not available
SystemEventQueueUtilities$ComponentWorkRequest.run() line: not available
InvocationEvent.dispatch() line: not available
EventQueue.dispatchEvent(AWTEvent) line: not available
EventDispatchThread.pumpOneEventForFilters(int) line: not available
EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: not available
EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: not available
EventDispatchThread.pumpEvents(int, Conditional) line: not available
EventDispatchThread.pumpEvents(Conditional) line: not available
EventDispatchThread.run() line: not available
Thread [DestroyJavaVM] (Suspended)
Daemon System Thread [D3D Screen Updater] (Suspended)
Object.wait(long) line: not available [native method]
D3DScreenUpdateManager.run() line: not available
Thread.run() line: not available
Daemon System Thread [TimerQueue] (Suspended)
Object.wait(long) line: not available [native method]
TimerQueue.run() line: not available
Thread.run() line: not available
Thread [Thread-3] (Suspended)
Thread.sleep(long) line: not available [native method]
JDCConnectionPool$ConnectionReaper.run() line: 93
Daemon Thread [SwingWorker-pool-1-thread-1] (Suspended)
Unsafe.park(boolean, long) line: not available [native method]
LockSupport.park(Object) line: not available
AbstractQueuedSynchronizer$ConditionObject.await() line: not available
LinkedBlockingQueue<E>.take() line: not available
ThreadPoolExecutor.getTask() line: not available
ThreadPoolExecutor$Worker.run() line: not available
Thread.run() line: not available

提前非常感谢。

最佳答案

its doInBackground does a SELECT query and after getting the result - updates the panel's model and calls the panel's refreshFromModel.

数据库查询是在doInBackground()中完成的。

模型的更新需要在process()方法中完成。

阅读 Swing 教程中关于 Concurrency 的部分了解更多信息。

关于Java Swing Workers 和组合框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5997339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com