Using Internal Frame Dialogs with JDesktopPane

Here’s a simple example that shows how this works. It also shows how you can make sure your container fills the desktop, even if the desktop changes size (since there’s no layout manager, this won’t happen automatically).

// DialogDesktop.java
//
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

// A frame that can easily support internal frame dialogs
public class DialogDesktop extends JFrame {

public DialogDesktop(String title) {
super(title);
setDefaultCloseOperation(EXIT_ON_CLOSE);

final JDesktopPane desk = new JDesktopPane( );
setContentPane(desk);

// Create our “real” application container; use any layout manager we want.
final JPanel p = new JPanel(new GridBagLayout( ));

// Listen for desktop resize events so we can resize p. This will ensure that
// our container always fills the entire desktop.
desk.addComponentListener(new ComponentAdapter( ) {
public void componentResized(ComponentEvent ev) {
Dimension deskSize = desk.getSize( );
p.setBounds(0, 0, deskSize.width, deskSize.height);
p.validate( );
}
});

// Add our application panel to the desktop. Any layer below the MODAL_LAYER
// (where the dialogs will appear) is fine. We’ll just use the default in
// this example.
desk.add(p);

// Fill out our app with a few buttons that create dialogs.
JButton input = new JButton(”Input”);
JButton confirm = new JButton(”Confirm”);
JButton message = new JButton(”Message”);
p.add(input);
p.add(confirm);
p.add(message);

input.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent ev) {
JOptionPane.showInternalInputDialog(desk, “Enter Name”);
}
});

confirm.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent ev) {
JOptionPane.showInternalConfirmDialog(desk, “Is this OK?”);
}
});

message.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent ev) {
JOptionPane.showInternalMessageDialog(desk, “The End”);
}
});
}

// A simple test program
public static void main(String[] args) {
DialogDesktop td = new DialogDesktop(”Desktop”);
td.setSize(350, 250);
td.setVisible(true);
}

Blog Traffic Exchange Related Websites
  • timemoneySave Time, Money and Space in Over 80 Ways If you're looking for handy gadgets, tools and various items that can save you time, money or space (or all three!) this list of more than 80 top products is just what you need. Everyone's got saving money on their minds these days. Some of us are always looking to......
  • Time For a Business Evaluation? We are only a few weeks into the New Year and now is a good time to ask how you are doing in your business.Did you vow in January to make some changes to help you grow?What were those changes?Did you include any kind of evaluation of your communications......
  • body1Targeting Problem Areas Most of us have at least one spot on our bodies that we would like to change. Commonly referred to as “problem areas,” if you are serious about making a change, you’ve got to find a way to target that area. While full body exercise is vital, there are many......
  • Discount Yoga Mats Selection, The How To Are you starting a new yoga practice in 2010, but you still require a discount yoga mat? These are some things you need to keep in mind when you purchase your discount yoga mats. Yoga provides its practioners many benefits, both mental and physical, improved concentration, increased strength, improved flexibility and even weight loss, and this is......
  • Sending a status report manually Sometimes you may want to manually send a status report or comments about a task. Here are two situations in which doing so might be desirable: The original task request (when you were assigned the task) did not include a request for automatic status updates. You were not assigned the......

6 Responses to “Using Internal Frame Dialogs with JDesktopPane”

  1. sory, sbnrny saya ga mo ngomntarin tulisan anda, saya cmn mau ngjak krja sm bwt naikin PR web/blog qt,,,

    klo anda mau, Copy kode di bawah, dan letakkan di Sidebar blog anda, setelah itu hubungi saya lewat koment ntar saya link balik..
    key,,,

    <a href="http://www.coretandedi.com/" title="Cicks Computer" target="_blank"> <img src="http://www.coretandedi.com/wp-content/uploads/2009/06/coretan-deddy.gif" border="0" alt="Clcks-Computer"></a>

  2. gak mudeng bro

  3. wah ini dia yang gue cari

  4. nice info sob…thanks

  5. trimakasih atas tutorial java-nya br0o..
    salam kenal ya??.,.

    Ooya punya source code java kalender yang kayak di komputer gak???….

    kalok ada aku mintak links-nya ya broo…

    —————————————————-

    email: trojan_crime@yahoo.com
    website: trojandecoder.blogspot.com

    —————————————————–

    trims,,

  6. very hard….confused…


Leave a Reply