JOptionPane.showMessageDialog in den Vordergrund vor allen anderen Anwendungen

Greq

Grünschnabel
Hallo zusammen,

habe da folgendes Problem:
wenn ich ein JOptionPane.showMessageDialog aufrufe erscheint dieser nur spontan im Vordergrund, wie kann ich diesen dauerhaft, in den Vordergrund (vor allen anderen Anwendungen) setzen ?


MFG
Greq
 
Hallo Greq,

schau mal hier:
Java:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class OptionPaneExample extends JFrame implements ActionListener {

	private JButton btn = new JButton("Show Message!");

	public OptionPaneExample() {
		this.setTitle(this.getClass().getCanonicalName());
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setAlwaysOnTop(true);
		this.setLocationByPlatform(true);

		this.add(btn);

		btn.addActionListener(this);

		this.pack();
		this.setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		JOptionPane jop = new JOptionPane();
		jop.setMessage("Hallo");
		JDialog dialog = jop.createDialog(this, "Message");
		dialog.setAlwaysOnTop(true);
		dialog.setModal(true);
		dialog.setVisible(true);
	}

	public static void main(String[] args) {
		new OptionPaneExample();
	}
}


Vg Erdal
 
Hallo nochmal,

also mit einem JFrame funktioniert es nun wunderbar,
was sieht es denn aber mit einem JOptionPane aus ?

Möchte meinen ursprünglichen Aufruf so ersetzen dass der Hauptvorgang unterbrochen wird und das JFrame abarbeitet und dann wieder mit dem Hauptvorgang weiter macht, wie eben ein JOptionPane.

String layerName;
layerName = JOptionPane.showInputDialog(TMapperMain.mapper, "Layername: ");

Ist dies mit einem JFrame auch möglich ?

Gruß
Greq
 
Vielen Dank für die schnelle Antwort,

habe es über JDialog gelöst, rufe nun aus einem modalen JDialog einen weiteren Modalen JDialog auf.

1. JDialog
Code:
...
DMapperReportReadyPanel tmp = new DMapperReportReadyPanel(repFrame);
...


2. JDialog
Code:
...
    public DMapperReportReadyPanel(Frame owner) {
    	
    	super(owner);
    	setModal(true);
    	
    	this.setSize(400, 100);
		this.setResizable(true);
		
        this.setTitle("Layername vergabe");
        this.setAlwaysOnTop(true);
        this.setLocationByPlatform(true);

        ...

        this.setVisible(true);

    }
...

Der 2.JDialog wird nun auch immer im Vordergrund ausgegeben.

Nochmal vielen Dank Erdal

Gruß
Greq
 

Neue Beiträge

Zurück