Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JDialog Hidden Behind JFrame

807600Aug 19 2007 — edited Aug 19 2007
Hi guys I have I have a program in Java and a problem. I have a main application which extends JFrame, then I have several JDialogs that popup when the user enters certain commands from the main application. The problem is that sometimes--not all the time the JDialogs are hidden behind the main JFrame. I feel so overwhelmed with this?I am a newbie?I need to know how I can create a class that extends JDialog so that it always paints on top of the Jframe?

I have read through so much material, and even considered just making the application on a Desktop so that nothing could get painted under it?but that had so many new problems.

This is the constructor code for the class that extends the JDialog :
public class JDialogBibleHope extends JDialog

other code (instance variables)??

//constructor
public JDialogBibleHope()

{
setModal(true);
setUndecorated(true);
Container container = getContentPane();
setSize(350,250);

JLabel outputPanel = new JLabel(new ImageIcon(getClass().getResource( "images/trueFalse.jpg")));

//this is for the done button
JButton trueButton = new JButton("True");
trueButton.setActionCommand("True");
JButton falseButton = new JButton("False");
falseButton.setActionCommand("False");


JPanel buttonPanel = new JPanel();
buttonPanel.add(trueButton);
buttonPanel.add(falseButton);
// Add listeners to each button
OptionHandler optionHandler = new OptionHandler();
trueButton.addActionListener(optionHandler);
falseButton.addActionListener(optionHandler);


JPanel main = new JPanel(new BorderLayout());
main.setBackground(black);
       main.add("Center",outputPanel);
        main.add("South",buttonPanel );
container.add(main,BorderLayout.CENTER);

    int width = 350;
    int height =250;
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width-width)/2;
    int y = (screen.height-height)/2;
    setBounds(x,y,width,height);


//System.out.println("The ButtonValue is:" + buttonNumber);
this.setAlwaysOnTop(true);
this.setVisible(true);
this.requestFocus();
this.toFront();

}//closes constructor
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2007
Added on Aug 19 2007
5 comments
2,468 views