0
が動作していないが実際に私は私が書かれている(5000) はrunメソッドの下に、以下のボタンのクリックに関する対話を作り出すプロジェクトに取り組んでのThread.sleepを経由して5秒でそれを配置していますのThread.sleep(5000)
5Sがそうするために私が確認する必要があります変更内容の後にそれが正常に動作しますが、複数のボタンの後、私はボタンをクリックしたときに
void showpopup(String p, String t) throws IOException {
JPanel app = new JPanel();
popup = new JFrame();
// app.setSize(300,400);
GridBagConstraints c1 = new GridBagConstraints();
app.setLayout(new GridBagLayout());
app.setVisible(true);
app.setBackground(new Color(39, 170, 225));
popup.setUndecorated(true);
popup.setSize(300, 100);
popup.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
JLabel header = new JLabel();
header.setText(p);
c1.gridx = 0;
c1.gridy = 0;
c1.weightx = 1.0f;
c1.weighty = 1.0f;
c1.insets = new Insets(5, 5, 5, 5);
c1.fill = GridBagConstraints.BOTH;
header.setFont(new Font("comfortaa", Font.BOLD, 15));
app.add(header, c1);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 0.3f;
constraints.weighty = 0.3f;
constraints.fill = GridBagConstraints.BOTH;
popup.add(app, constraints);
BufferedImage Butico = ImageIO.read(new File("C:/Users/utkarsh/Desktop/close.png"));
JButton close = new JButton(new ImageIcon(Butico));
close.setContentAreaFilled(false);
close.setBorder(BorderFactory.createEmptyBorder());
c1.gridx = 1;
c1.weightx = 0f;
c1.weighty = 0f;
c1.insets = new Insets(5, 5, 5, 5);
c1.fill = GridBagConstraints.NONE;
c1.anchor = GridBagConstraints.NORTH;
close.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
popup.dispose();
}
});
app.add(close, c1);
JPanel cont = new JPanel(new GridBagLayout());
// cont.setSize(arg0, arg1);
String a = "hello";
JLabel text = new JLabel("<HtML>" + t);
text.setAlignmentX(Component.LEFT_ALIGNMENT);
cont.setVisible(true);
cont.setBackground(new Color(241, 242, 242));
c1.gridx = 0;
c1.gridy = 0;
c1.weightx = 1.0f;
c1.weighty = 1.0f;
c1.insets = new Insets(5, 5, 5, 5);
c1.anchor = GridBagConstraints.NORTH;
c1.fill = GridBagConstraints.BOTH;
cont.add(text, c1);
constraints.gridx = 0;
constraints.gridy += 1;
constraints.weightx = 2.5f;
constraints.weighty = 2.5f;
constraints.fill = GridBagConstraints.BOTH;
popup.add(cont, constraints);
text.setFont(new Font("Comfortaa", Font.PLAIN, 12));
text.setForeground(Color.DARK_GRAY);
header.setForeground(Color.WHITE);
popup.getRootPane().setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new Color(188, 188, 188)));
popup.setVisible(true);
Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
Insets th = Toolkit.getDefaultToolkit().getScreenInsets(popup.getGraphicsConfiguration());
popup.setLocation(s.width - popup.getWidth() - 5, s.height - th.bottom - popup.getHeight() - 5);
popup.setAlwaysOnTop(true);
new Thread() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
popup.dispose();
}
}
}.start();
}
今すぐクリックした複数のJDialogのポップアップ 表示され、最後のものだけが配置されますすべてのJDialogボックスを閉じる
編集してください、見てください –
'Thread.sleep()の代わりに[' java.swing.Timer'](https://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html)を使用してください。 ) '。 – trashgod