| 1 | |
package org.jtheque.utils.ui; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import javax.swing.BorderFactory; |
| 20 | |
import javax.swing.JComponent; |
| 21 | |
import javax.swing.JLabel; |
| 22 | |
import javax.swing.JPanel; |
| 23 | |
import javax.swing.JTextField; |
| 24 | |
import javax.swing.Popup; |
| 25 | |
import javax.swing.PopupFactory; |
| 26 | |
import javax.swing.SwingUtilities; |
| 27 | |
import java.awt.Color; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 0 | final class DisplayPopupThread extends Thread { |
| 35 | 0 | private final PopupFactory factory = PopupFactory.getSharedInstance(); |
| 36 | |
private final JTextField owner; |
| 37 | |
private final JComponent content; |
| 38 | |
|
| 39 | |
private Popup popup; |
| 40 | |
|
| 41 | |
private static final int DISPLAY_TIME = 2000; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
DisplayPopupThread(JTextField field) { |
| 49 | 0 | super(); |
| 50 | |
|
| 51 | 0 | owner = field; |
| 52 | |
|
| 53 | 0 | content = new JPanel(); |
| 54 | 0 | content.add(new JLabel("Too long")); |
| 55 | 0 | content.setBackground(Color.white); |
| 56 | 0 | content.setBorder(BorderFactory.createEtchedBorder()); |
| 57 | 0 | } |
| 58 | |
|
| 59 | |
@Override |
| 60 | |
public void run() { |
| 61 | 0 | popup = createPopup(); |
| 62 | |
|
| 63 | 0 | SwingUtilities.invokeLater(new Runnable() { |
| 64 | |
@Override |
| 65 | |
public void run() { |
| 66 | 0 | popup.show(); |
| 67 | 0 | } |
| 68 | |
}); |
| 69 | |
|
| 70 | |
try { |
| 71 | 0 | Thread.sleep(DISPLAY_TIME); |
| 72 | 0 | } catch (InterruptedException e) { |
| 73 | |
|
| 74 | 0 | } |
| 75 | |
|
| 76 | 0 | interrupt(); |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
@Override |
| 80 | |
public void interrupt() { |
| 81 | 0 | close(); |
| 82 | |
|
| 83 | 0 | super.interrupt(); |
| 84 | 0 | } |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
private Popup createPopup() { |
| 92 | 0 | return factory.getPopup( |
| 93 | |
owner, content, |
| 94 | |
owner.getLocationOnScreen().x + owner.getWidth() / 2, |
| 95 | |
owner.getLocationOnScreen().y + owner.getHeight() / 2); |
| 96 | |
} |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
void close() { |
| 102 | 0 | SwingUtilities.invokeLater(new Runnable() { |
| 103 | |
@Override |
| 104 | |
public void run() { |
| 105 | 0 | popup.hide(); |
| 106 | 0 | } |
| 107 | |
}); |
| 108 | 0 | } |
| 109 | |
} |