This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

closing a JDialog with a button  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
moin,

i have a problem with the following code:

i create a frame, than a dialog and with a click on the close button the dialog should be closed, so that i can work in the frame.
the control-line "hello" is displayed in the console, but the dialog doesn't disappear.

please help me...
 
Rancher
Posts: 1926
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// Should work now, look at the commented line below you should get the idea, a new JDailog object was getting created.
package testen;
import java.awt.event.*;
import javax.swing.*;

public class ProbDialogClose {

static JFrame f = new JFrame("test");
static JDialog dialog = new JDialog( f, true );

ProbDialogClose()
{
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.setVisible( true );
showWelcomeMessage();

}

private void showWelcomeMessage(){
//JDialog dialog = new JDialog( f, true );
dialog.setSize( 450, 400 );
dialog.setLayout(null);

JButton closeButton = new JButton("Fenster schließen");
closeButton.setSize(150, 30);
closeButton.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
closeWelcomeMessage();
}
} );
dialog.add( closeButton );
dialog.setVisible( true );
}

private void closeWelcomeMessage(){
System.out.println("hello");
dialog.setVisible(false);
dialog.dispose();
}

public static void main( String[] args ) {
new ProbDialogClose();
}
}
 
Klaus Hansen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot....
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!