JDialog

Hello all,
I have JDialog window needs to on fixed position on screen. It should not be resized or moved to new location by user.
Help is needed.....
THanks

Uhm, read the API docs?
setResizable and setLocation
As far as always in the same place, setAlwaysOnTop will help some, and maybe a FocusListener that sets the location anew every time the window gets Focus? (Although I find this to be a very bogus requirement).
Once you've tried all those out, if it doesn't work the way you want, post your code and state your exact problem.

Similar Messages

  • Problem with jDialog in a JFrame

    Hello to everyone...i'm newby java GUI developer, and i've got a problem with a JDialog within a JFrame...
    I made a JFrame which creates a new customized JDialog in his contructor, like this:
    MioJdialog dlg = new MioJdialog(this, true);
    dlg.setVisible(true);
    ...The "MioJdialog" class store his JFrame parent under a private attribute, in this way:
    class MioJdialog {...
    private Frame parent;
    public MioJdialog (Frame parent, boolean modal){
        this.parent=parent;
    ....}and here's the problem: when i try to close the parent JFrame with a command like this:
    parent.dispose();
    ( in order to close the whole window), sometimes happens that the JFrame is still visible on the screen...and i don't know why...
    got some hints?
    thanks to everyone!
    Edited by: akyra on Jan 14, 2008 4:36 AM
    Edited by: akyra on Jan 14, 2008 4:37 AM
    Edited by: akyra on Jan 14, 2008 4:37 AM

    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
    http://homepage1.nifty.com/algafield/sscce.html
    Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
    http://forum.java.sun.com/help.jspa?sec=formatting

  • Problem with JDialogs and Threads

    Hi. I'm new to this forum and I hope I'm not asking a repeat question. I didn't find what I needed after a quick search of existing topics.
    I have this problem with creating a new JDialog from within a thread. I have a class which extends JDialog and within it I'm running a thread which calls up another JDialog. My problem is that the JDialog created by the Thread does not seem to function. Everything is unclickable except for the buttons in the titlebar. Is there something that I'm missing out on?

    yeah, bad idea, don't do that.

  • Problem with JDialogs

    Hi All,
    I have a problem with JDialogs in my standalone application. This app pops-up multiple JDialogs, say a stack of JDialogs.
    I have a standalone application which runs as a JFrame, call it JFrame1, which is working fine. JFrame1 pops-up a JDialog, on some button click on JFrame1, call it JDialog1, which is also working fine. Now JDialog1 pops-up another JDialog, again on some button click on JDialog1, call it JDialog2, which is too working fine. But, after I finish with JDialog2 and dispose it my JDialog1 is not working fine, though that is the front dialog at present.
    Any ideas why JDialog1 is not working fine? Am I missing anything?
    Thanks,
    Srinivas.

    Hi,
    I have a component called DateComponent that works similar to a JComboBox. When you click a small button of DateComponent, it pops-up a Calendar similar to the drop down list of JComboBox and user can pick a date from it. It gets closed when it loses focus.
    I have this DateComponent on JFrame1, JDialog1 and JDialog2. The Calendar is not being diaplayed on JDialog1 upon clicking the small button of DateComponent after JDialog2 is disposed. But it is being diaplayed properly on JDialog1 before JDialog1 opens JDialog2. What could be wrong?
    I am using JDK1.3.1.
    Thanks,
    Srinivas.

  • Problem with refreshing JFrames and JDialogs

    My program is based on few JDialogs and one JFrame. I'm still changing them, one time one of the JDialogs is visible, other time JFrame. During this change I call dispose() for one window or frame and I create (if it wasn't created before) other component and call setVisible(true) for it. Problem is that sometimes (only sometimes! like 5% of calls) my windows appears but they are not refreshing (not showing new objects added to their lists or sth like that) until I resize my window by dragging mouse on the edge of it. Is there anyway to ensure that window will be displayed properly?

    I ran into this problem about a year ago...so I don't really remember but I think a call to validate(), or paint() or repaint() or something like that should do the trick (forgive me for not knowing the exact one but as I said it has been a while). Its been about that year since I stopped coding in java and moved to c#. You want the window to redraw its self what ever that is.

  • Detecting a JDialog opening and closing

    Hey everyone,
    This is a simple question, or at least, it should be :). I need a Timer to start when a JDialog opens and stop when it closes so a cute icon animation shows.
    So far, I managed to detect when the window opens, but not when it closes. This code is at the JDialog constructor:
    addWindowListener(new WindowAdapter()
                @Override
                public void windowClosed(WindowEvent we)
                    System.out.println("\t\t\t\twindowClosed");
                    busyIconTimer.stop();
                @Override
                public void windowOpened(WindowEvent we)
                    System.out.println("\t\t\t\twindowOpened");
                    busyIconTimer.start();
            });When I call "setVisible(true)", the windowClosed event is raised.
    When I call "setVisible(false", no event is called whatsoever (tried all the events available).
    Instead, if I call "mydialog.dispose()", the windowClosed event is called correctly.
    But after this, if I call "setVisible(true)" again, the windowOpened isn't called.
    Can anyone help me? :)
    Thanks in advance.

    I find that setVisible(false) calls windowDeactivate:
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class DialogStateListener
      private static void createAndShowUI()
        final JFrame frame = new JFrame("DialogStateListener");
        final JDialog dialog = new JDialog(frame, "Dialog", true);   
        JButton showDialogBtn = new JButton("Show Dialog");
        showDialogBtn.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            dialog.setVisible(true);
        frame.getContentPane().add(showDialogBtn);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        JButton setVisibleFalseBtn = new JButton("setVisible(false)");
        JButton disposeBtn = new JButton("dispose");
        setVisibleFalseBtn.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            dialog.setVisible(false);
        disposeBtn.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            dialog.dispose();
        dialog.setPreferredSize(new Dimension(200, 200));
        JPanel contentPane = (JPanel)dialog.getContentPane();
        contentPane.setLayout(new FlowLayout());
        contentPane.add(setVisibleFalseBtn);
        contentPane.add(disposeBtn);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.addWindowListener(new WindowListener()
          public void windowActivated(WindowEvent e)
            System.out.println("window activated");
          @Override
          public void windowClosed(WindowEvent e)
            System.out.println("window closed");
          @Override
          public void windowClosing(WindowEvent e)
            System.out.println("window closing");
          @Override
          public void windowDeactivated(WindowEvent e)
            System.out.println("window deactivated");
          @Override
          public void windowDeiconified(WindowEvent e)
            System.out.println("window deiconified");
          @Override
          public void windowIconified(WindowEvent e)
            System.out.println("window iconified");
          @Override
          public void windowOpened(WindowEvent e)
            System.out.println("window opened");
      public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
          public void run()
            createAndShowUI();
    }

  • IMAGE NOT DISPLAYED OVER JButton ON JDialog

    Hi,
    I am trying to display an image over a JButton inside a JDialog(pops up on button click from an applet). But it is invisible. But I am sure that it is drawn on the ContentPane since when i click partially/half at the position
    of the JButton I could see the JButton with the image. Actualy I am resizing the JDialog since I have two buttons, one to minimise and the other two maximise the size of the JDailog.
    All the buttons are in place but not visible neither at the first place nor when the JDialog is resized.
    The code is as follows:
    package com.dataworld.gis;
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import javax.swing.*;
    public class PrintThisPolygon extends JDialog {
         protected Image image;
         protected JButton print;
         protected JButton resize;
         protected JButton desize;
         private int pX=0, pY=0, pWidth=0, pHeight=0;
         public PrintThisPolygon(JFrame parent, Viewer viewer) {
              super(parent, "Print Polygon", true);
              this.setModal(false);
              getContentPane().setLayout(null);
              image = this.viewer.getScreenBuffer();
              pane = new Panel();
              print = new JButton("print", new ImageIcon("images/print.gif"));
              print.setBounds(0,5,50,20);
              print.setEnabled(true);
              print.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent ae){
                        print();
              resize = new JButton("+", new ImageIcon("images/print.gif"));
              resize.setBounds(55,5,50, 20);
              resize.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent ae){
                        resizePlus();
              desize = new JButton("-", new ImageIcon("images/print.gif"));
              desize.setBounds(105,5,50, 20);
              desize.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent ae){
                        resizeMinus();
              getContentPane().add(print);
              getContentPane().add(resize);
              getContentPane().add(desize);
    public String getAppletInfo() {
         return "Identify Polygon\n"
    public void paint(Graphics g){
         System.out.println("Paint : pX " + pX + " pY :" + pY);
         g.drawImage(image, pX, pY, pWidth, pHeight, getBackground(), this);
    protected void print() {
         ImagePrint sp = new ImagePrint(this.viewer);
    public void resizeMinus(){
         repaint();
    public void resizePlus(){
         repaint();
    Can anybody has any clue. Can anybody help me out.
    Thanx

    I added resize code for those buttons and ended up with repaint problems too. When you manually resized the window everything was fine again. After a bit of digging around I found you need to call validate on the dialog and then things work.
    IL,
    There is the new scaling version of the code I modified above:package forum.com.dataworld.gis;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class PanelPaintFrame extends JFrame {
         public static void main(String[] args) {
              PanelPaintFrame frame = new PanelPaintFrame ();
              frame.setVisible (true);
         public PanelPaintFrame ()  {
              setBounds (100, 100, 600, 600);
              setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              JButton showPrintDialogButton = new JButton ("Show Print Dialog...");
              JPanel buttonPanel = new JPanel ();
              buttonPanel.add (showPrintDialogButton);
              getContentPane ().add (buttonPanel);
              showPrintDialogButton.addActionListener (new ActionListener ()  {
                   public void actionPerformed (ActionEvent e)  {
                        PrintThisPolygon printDialog = new PrintThisPolygon (PanelPaintFrame.this);
                        printDialog.show();
              pack ();
         public class PrintThisPolygon extends JDialog {
              protected ImageIcon myOrigonalImage = null;
              protected Image image;
              protected JButton print;
              protected JButton resize;
              protected JButton desize;
              private int pX=0, pY=0, pWidth=0, pHeight=0;
              JPanel pane = null;
              public PrintThisPolygon(JFrame parent/*, Viewer viewer*/) {
                   super(parent, "Print Polygon", true);
    //               this.setModal(false);
                   getContentPane().setLayout(null);
                   //  Substitute my own image
                   myOrigonalImage = new ImageIcon (PrintThisPolygon.class.getResource ("images/MyCoolImage.jpg"));
                   //  Start off full size
                   pWidth = myOrigonalImage.getIconWidth();
                   pHeight = myOrigonalImage.getIconHeight();
                   image = myOrigonalImage.getImage ().getScaledInstance(pWidth, pHeight, Image.SCALE_DEFAULT);
    //               image = this.viewer.getScreenBuffer();
    //               pane = new Panel();
                   //  Create a JPanel to draw the image
                   pane = new JPanel(){
                        protected void paintComponent(Graphics g)  {
                             System.out.println("Paint : pX " + pX + " pY :" + pY);
                             g.drawImage(image, pX, pY, pWidth, pHeight, getBackground(), this);
                   pane.setBounds (0, 0, pWidth, pHeight);
                   //  Load the button image using a URL
                   print = new JButton("print", new ImageIcon(PrintThisPolygon.class.getResource ("images/print.gif")));
    //               print = new JButton("print", new ImageIcon("images/print.gif"));
                   print.setBounds(0,5,55,20);
                   print.setEnabled(true);
                   print.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent ae){
                             print();
                   resize = new JButton("+", new ImageIcon("images/print.gif"));
                   resize.setBounds(55,5,50, 20);
                   resize.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent ae){
                             resizePlus();
                   desize = new JButton("-", new ImageIcon("images/print.gif"));
                   desize.setBounds(105,5,50, 20);
                   desize.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent ae){
                             resizeMinus();
                   //  Setup a transparent glass panel with no layout manager
                   JPanel glassPanel = new JPanel ();
                   glassPanel.setLayout (null);
                   glassPanel.setOpaque (false);
                   //  Add the image panel to the dialog
                   getContentPane().add(pane);
                   //  Add the buttons to the glass panel
                   glassPanel.add(print);
                   glassPanel.add(resize);
                   glassPanel.add(desize);
                   //  Set our created panel as the glass panel and turn it on
                   setGlassPane (glassPanel);
                   glassPanel.setVisible (true);
                   setBounds (100, 100, pWidth, pHeight);
    //               setBounds (100, 100, 500, 300);
              public String getAppletInfo() {
                   return "Identify Polygon\n";
    //          public void paint(Graphics g){
    //          protected void paintComponent(Graphics g)  {
    //               System.out.println("Paint : pX " + pX + " pY :" + pY);
    //               g.drawImage(image, pX, pY, pWidth, pHeight, getBackground(), this);
              protected void print() {
                   //  Pretend to print
    //               ImagePrint sp = new ImagePrint(this.viewer);
                   System.out.println ("Print view...");
              public void resizeMinus(){
                   //  Scale the image down 10%
                   int scaledWidth = pWidth - (int)(pWidth * 0.1);
                   int scaledHeight = pHeight - (int)(pHeight * 0.1);
                   scaleImage (scaledWidth, scaledHeight);
              public void resizePlus(){
                   //  Scale the image up 10%
                   int scaledWidth = pWidth + (int)(pWidth * 0.1);
                   int scaledHeight = pHeight + (int)(pHeight * 0.1);
                   scaleImage (scaledWidth, scaledHeight);
              private void scaleImage (int scaledWidth, int scaledHeight)  {
                   //  Create a new icon for drawing and retrieve its actuall size
                   image = myOrigonalImage.getImage ().getScaledInstance (scaledWidth, scaledHeight, Image.SCALE_DEFAULT);
                   pWidth = scaledWidth;
                   pHeight = scaledHeight;
                   //  Resize
                   setSize (pWidth, pHeight);
                   pane.setSize (pWidth, pHeight);
                   validate();
    }

  • JDialog not displaying correctly

    Hi all,
    Im having this problem with displaying a JDialog. I have a lengthy delay in my app and want to display an animated GIF while the user is waiting. The below code is what im trying to run. The JDialog wil display, but the title text, message text and the ImageIcon are not displayed on the JDialog. Anyone know what is wrong? Do i have to wait on the Image to load before i .show the dialog? But that wouldn't explain why the text doesn't show. Any help appreciated
    Code im trying to run, RemoteAdminMain.java
        WaitingDialog dialog = new WaitingDialog(this, "Connection...", false, "Creating Connection");
        try {
          //Create the connection...
          dialog.show();
          RemoteAdminMain.nc = NetConnection.createNetConnection(nodeAddress, Global.sessionUsername, Global.sessionPassword);
          dialog.dispose();
        } catch (Exception e) {
          dialog.dispose();
          JOptionPane.showMessageDialog(null, "Error", "Error", JOptionPane.ERROR_MESSAGE);
          e.printStackTrace();
          return;
    The Dialog code: WaitingDialog.java
    public class WaitingDialog extends JDialog {
      private JPanel panel1 = new JPanel();
      private BorderLayout borderLayout1 = new BorderLayout();
      private JLabel jLabel1 = new JLabel();
      private JLabel jLabel2 = new JLabel();
      public WaitingDialog(Frame frame, String title, boolean modal, String message) {
        super(frame, title, modal);
        try {
          jLabel2.setText(message);
          jbInit();
          pack();
        catch(Exception ex) {
          ex.printStackTrace();
        //Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension dialogSize = getSize();
        if (dialogSize.height > screenSize.height) {
          dialogSize.height = screenSize.height;
        if (dialogSize.width > screenSize.width) {
          dialogSize.width = screenSize.width;
        setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
      public WaitingDialog() {
        this(null, "", false, "");
      void jbInit() throws Exception {
        panel1.setLayout(borderLayout1);
        jLabel2.setToolTipText("");
        jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel2.setHorizontalTextPosition(SwingConstants.CENTER);
        jLabel2.setText("message");
        jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
        ImageIcon icon = new ImageIcon(com.tempo.netservice.RemoteAdminMain.class.getResource("swing.gif"));
        icon.setImageObserver(jLabel1);
        jLabel1.setIcon(icon);
        this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        this.setResizable(false);
        this.setTitle("");
        getContentPane().add(panel1);
        panel1.add(jLabel1, BorderLayout.CENTER);
        panel1.add(jLabel2,  BorderLayout.SOUTH);
    }

    I fear the problem isn't with the JDialog itself, everything is from from that point of view. I forgot to mention that if you set it as Modal, it will display fine (however, the modal method is blocking, meaning the createNetConnection method will not be executed until the dialog is closed, entirly defeating the purpose.
    I believe the problem is that the createNetConnection function stops the rest of the JDialog from loading. So i guess my question to begin with is, is there anyway to completly display and paint the JDialog before allowing it to continue onto the next function?

  • Open a JDialog from an JApplet

    Hello,
    I have an applet and I want to open a separate window. The problem is that I want this window to be modal, and therefore I have to use a JDialog, but a JDialog needs an owner that can only be a JFrame or a JDialog, so I cannot use the JApplet as an owner. I tried to set the owner to null, but then if the user changes the focus to another window in his/her OS, and then returns to the browser, the JDialog does not reappear, so the applet is stuck!
    Does anybody have an idea how I can solve this problem?
    Thanks very much.

    Yes, cuz all applets have a frame....
    Frame f =
    (Frame)SwingUtilities.getAncestorOfClass(Frame.class,
    this);Thank you very much. I will try this solution.

  • How can I change the layout on this JDialog?

    Hi , I have the following Dialog with some content. As of now, the line after the separator is displayed in two lines. I was looking for a way to show that in one line and change the column widths a bit so that the rest of the content can each be shown on one line as well, according to the look and feel of a table.
    Here's the code:Please download [TableLayout.jar|http://java.sun.com/products/jfc/tsc/articles/tablelayout/apps/TableLayout.jar] in order to compile.
    Thanks!
    import layout.TableLayout;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JSeparator;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextPane;
    import javax.swing.text.StyledEditorKit;
    public class MyDialogTest implements layout.TableLayoutConstants {
         JTabbedPane pane;
         JDialog myDialog;
         JTextPane infoPanel;
        public MyDialogTest() {
             myDialog = new JDialog();
             myDialog.setTitle("MyDialogTest");
             pane = new JTabbedPane();
             JPanel panel = new JPanel(new BorderLayout());
             panel.add(makeTab(), BorderLayout.CENTER);
             pane.addTab("About", panel);
             myDialog.getContentPane().add(pane);
             myDialog.setSize(500, 620);
             myDialog.setResizable(false);
             myDialog.setVisible(true);
        private Component makeTab() {
             JPanel aboutPanel = new JPanel();
            double [][] size = {{PREFERRED, FILL},{PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, FILL}};
            TableLayout layout = new TableLayout(size);
            aboutPanel.setLayout(layout);
            JLabel headerLabel = new JLabel("About This Application");
            aboutPanel.add(headerLabel, "0, 0, 1, 0");
            aboutPanel.add(new JLabel("Version 4.1"), "0, 1, 1, 1");
            aboutPanel.add(new JLabel(" "), "0, 2, 1, 2");
            aboutPanel.add(new JLabel("Customer Service: 1-800-888-8888"), "0, 3, 1, 3");
            JLabel yahooUrl = new JLabel("www.yahoo.com");
            aboutPanel.add(yahooUrl, "0, 4");
            aboutPanel.add(new JLabel(" "), "0, 5");
            aboutPanel.add(new JSeparator(), "0, 6, 1, 6");
            aboutPanel.add(new JLabel(" "), "0, 7");
            infoPanel = new JTextPane();
            infoPanel.setEditable(false);
            infoPanel.setEditorKit(new StyledEditorKit());
            infoPanel.setContentType("text/html");
            makeInfoPanel();
            aboutPanel.add(infoPanel, "0, 8, 1, 8");
            JButton copyToClipboardButton = new JButton("Button1");
            JButton moreInformationButton = new JButton("Button2");
            JPanel buttonPanel = new JPanel();
            buttonPanel.add(copyToClipboardButton);
            buttonPanel.add(moreInformationButton);
            aboutPanel.add(buttonPanel, "0, 9");
            return aboutPanel;
        private void makeInfoPanel() {
              StringBuffer infoPaneContent = new StringBuffer("<html><head></head><body><table>");
              infoPaneContent.append("<tr><td>Version 4.1 (build  111708-063624"+ "</td></tr>");
              infoPaneContent.append("<tr><td>Customer IP Address:</td>&nbsp <td>10.53.62.11</td></tr>");
              infoPaneContent.append("<tr><td>JMS Server:</td>&nbsp <td>myserver</td></tr>");
              infoPaneContent.append("<tr><td>Quote Server:</td>&nbsp <td>qs2w62m3/qs106w60m3</td></tr>");
              infoPaneContent.append("<tr><td>Login ID:</td>&nbsp <td>programmer girl</td></tr>");
              infoPaneContent.append("<tr><td>Java Version:</td> &nbsp<td>"+ System.getProperty("java.version") + "</td></tr>");
              infoPaneContent.append("<tr><td>Operating System:</td> &nbsp<td>"+ System.getProperty("os.name") + " "+ System.getProperty("os.version") + " ("+ ")" + "</td></tr>");
             infoPaneContent.append("<tr><td>Browser Version:</td>&nbsp <td>"+ "Mozilla/4.0(compatible: MSIE 6.0; Windows NT 5.1; SV!; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648" + "</td></tr>");
              Runtime rt = Runtime.getRuntime();
              infoPaneContent.append("<tr><td>Free Memory (KB):</td>&nbsp <td>("+ rt.freeMemory() / 1000 + " / " + rt.totalMemory() / 1000+ ")</td></tr>");
              infoPaneContent.append("<tr><td>Symbols In Use:</td>&nbsp<td>symbol</td></tr>");
              infoPaneContent.append("<tr><td>JMS :</td>&nbsp<td>connected</td></tr>");
              infoPaneContent.append("<tr><td>Market Data :</td>&nbsp<td>connected</td></tr>");
              infoPaneContent.append("<tr></tr>");
              infoPaneContent.append("<tr></tr>");
              infoPaneContent.append("</table></body></html>");
              infoPanel.setText(infoPaneContent.toString());
         public static void main(String[] args) {
              MyDialogTest test = new MyDialogTest();
    }

    Just sign out and sign in with your UK Apple ID
    Edit: If you press your name on this page (top left), you get "Actions" on the right side. Here you can change timezone, location etc.

  • Hiding a JDialog invoked in a Thread.

    Hi,
    I have a Swing application that starts a Thread that in turn creates a modal JDialog. I need to use the Thread so that I can wait around for information entered in the Dialog while leaving the rest of the application interactive. However, when I do this, any attempt I try (hide and setVisible(false)) to remove the dialog visibly from the screen fails. I initialize the Dialog with null as the Parent frame. Is that my problem, or am I doing something else wrong?
    Thanks,
    Jason Mazzotta

    Generally you can close the dialog only from the event-dispatching thread. If you want to do it from another thread, you have to do the following:
    instead of calling
    setVisible( false );call
            SwingUtilities.invokeLater(
            new Runnable()
                public void run()
                     waitDlg.setVisible( false );

  • How to load a background Image on a JDialog object

    Hi All, Actually i am new to java programing and i am stuck in this problem. I am developing a java application which is dialog based (using JDialog objects) and i want to load a background image on my dialog. I hope this could be done and i really appreciate your help because i must deliver this project and this is a user interface requirement.

    Try something along the lines of this: Create a new class called BackgroundImagePanel and have it extend JPanel.
    Have an attribute in the class for your image, and a method to set it.
    Override isOpaque() to return true.
    Override the paintComponenet method as such:
    public void paintComponent (Graphics g) {
    super.paintComponent(g);
    if( image == null ) return;
    Icon icon = new ImageIcon(image);
    icon.paintIcon(this, g, x, y);
    Add this panel to your JDialog and then add other component to this panel.
    You might have to tweak this a bit, but it should get you close...
    Bill

  • Displaying one JDialog window at a time

    Hi,
    I'm having some trouble trying to write a code where only one JDialog window appears at one time.
    -so when one jdialog box appears, no other jdialog can appear
    -I was thinking about using a boolean but it didn't work at all
    Here's my code:
    iimport javax.swing.*;
    import java.awt.event.*;
    public class Data extends JFrame
         JMenuItem existingRental;
         JMenuItem newRental;
         boolean one = true;
         public Data(){
              createMainMenu();
              setSize(350, 100);
              setVisible(true);
              setLocationRelativeTo(null);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public static void main(String[] args){
              new Data();
         private void createMainMenu(){
              JMenuBar mainMenuBar = new JMenuBar();  //notice - used JMenuBar
              setJMenuBar(mainMenuBar);
              JMenu windowMenu = new JMenu("Window");
              windowMenu.setMnemonic('w');
              mainMenuBar.add(windowMenu);
              newRental = new JMenuItem("New Rental");
              newRental.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
              newRental.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                        new Rental();
                        one = true;
                        if(!one)
                             new ExistingRentals();
              existingRental = new JMenuItem("Existing Rentals");
              existingRental.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
              existingRental.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                        new ExistingRentals();
                        one = true;
                        if(!one)
                             new Rental();
              windowMenu.add(newRental);
              windowMenu.add(existingRental);
    }JDialog two
    import javax.swing.*;]
    import java.awt.*;
    public class ExistingRentals extends JDialog
         private JList list;
         private JScrollBar scrollHorizontal;
         public ExistingRentals()
              existingRentalAgreement();
              setTitle("Rental List");
              setSize(200, 500);
              setVisible(true);
              setLocationRelativeTo(null);
         public void existingRentalAgreement()
              Container container = getContentPane();
              container.setLayout(new BorderLayout());
              list = new JList();
              scrollHorizontal = new JScrollBar(JScrollBar.HORIZONTAL);
              add(scrollHorizontal, BorderLayout.SOUTH);
              scrollHorizontal.add(list);
    }

    What if you made your jdialog modal. this can be done by passing a boolean parameter set to "true" to the JDialog super constructor. Here is what I mean with some other minor changes:
    ExistingRentals class ----------------------------------------
    import javax.swing.*;
    import java.awt.*;
    public class ExistingRentals extends JDialog
        private JList list;
        private JScrollBar scrollHorizontal;
        public ExistingRentals(JFrame parent, String title)
            super(parent, true); // true here makes dialog modal.[captain.obvious]false does the opposite[/captain.obvious]
            existingRentalAgreement();
            setTitle(title);
            setSize(200, 500);
            setVisible(true);
            setLocationRelativeTo(null);
        public void existingRentalAgreement()
            Container container = getContentPane();
            container.setLayout(new BorderLayout());
            list = new JList();
            scrollHorizontal = new JScrollBar(JScrollBar.HORIZONTAL);
            add(scrollHorizontal, BorderLayout.SOUTH);
            scrollHorizontal.add(list);
    import javax.swing.*;
    import java.awt.event.*;
    public class Data extends JFrame
        JMenuItem existingRental;
        JMenuItem newRental;
        boolean one = true;
        public Data() {
            createMainMenu();
            setSize(350, 100);
            setVisible(true);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public static void main(String[] args)
            new Data();
        private void createMainMenu()
            JMenuBar mainMenuBar = new JMenuBar(); // notice - used JMenuBar
            setJMenuBar(mainMenuBar);
            JMenu windowMenu = new JMenu("Window");
            windowMenu.setMnemonic('w');
            mainMenuBar.add(windowMenu);
            newRental = new JMenuItem("New Rental");
            newRental.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
                    ActionEvent.CTRL_MASK));
            newRental.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    newRentalAction(e);
            existingRental = new JMenuItem("Existing Rentals");
            existingRental.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,
                    ActionEvent.CTRL_MASK));
            existingRental.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    existingRentalAction(e);
            windowMenu.add(newRental);
            windowMenu.add(existingRental);
        private void existingRentalAction(ActionEvent e)
            new ExistingRentals(this, "Existing Rental List");
            // one = true;
            // if (!one) new Rental();
        private void newRentalAction(ActionEvent e)
            // one = true;
            // if (!one)
            new ExistingRentals(this, "New Rental List");
            // new Rental();
    }

  • Tranfer data from a jdialog to a frame!

    Hello, everybody?!That is my doubt!!There's a jtable inside a jdialog, when a row was selected, and the "enter" key was pressed, i'd like to send the data to a frame (main).How could i create that?Thanks!!

    here's something rough - just sets the selection as the label's text. modify for the row data
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    class Testing
      JLabel selection = new JLabel("Selected Value = ");
      public void buildGUI()
        JButton btn = new JButton("Get Selection");
        final JFrame f = new JFrame();
        f.getContentPane().add(selection,BorderLayout.NORTH);
        f.getContentPane().add(btn,BorderLayout.SOUTH);
        f.setSize(200,80);
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
        btn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            final JDialog d = new JDialog();
            Object[] cols = {"A","B","C"};
            Object[][] data = {{1,2,3},{4,5,6},{7,8,9},{10,11,12},{13,14,15}};
            final JTable table = new JTable(data,cols){
              public boolean isCellEditable(int row, int col){
                return false;
            JScrollPane sp = new JScrollPane(table);
            sp.setPreferredSize(new Dimension(100,100));
            d.setModal(true);
            d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
            d.getContentPane().add(sp);
            d.pack();
            d.setLocationRelativeTo(f);
            Action enterAction = new AbstractAction(){
              public void actionPerformed(ActionEvent ae){
                selection.setText("Selected Value = " +
                table.getValueAt(table.getSelectedRow(),table.getSelectedColumn()));
                d.dispose();
            InputMap im = table.getInputMap(JTable.WHEN_FOCUSED);
            KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
            im.put(enter, "enter");
            table.getActionMap().put(im.get(enter), enterAction);
            d.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }

  • Problems with 'background' JFrame focus when adding a modal JDialog

    Hi all,
    I'm trying to add a modal JDialog to my JFrame (to be used for data entry), although I'm having issues with the JFrame 'focus'. Basically, at the moment my program launches the JFrame and JDialog (on program load) fine. But then - if I switch to another program (say, my browser) and then I try switching back to my program, it only shows the JDialog and the main JFrame is nowhere to be seen.
    In many ways the functionality I'm looking for is that of Notepad: when you open the Find/Replace box (albeit it isn't modal), you can switch to another program, and then when you switch back to Notepad both the main frame and 'JDialog'-esque box is still showing.
    I've been trying to get this to work for a couple of hours but can't seem to. The closest I have got is to add a WindowFocusListener to my JDialog and I hide it via setVisible(false) once windowLostFocus() is fired (then my plan was to implement a similar functionality in my JFrame class - albeit with windowGainedFocus - to show the JDialog again, i.e. once the user switches back to the program). Unfortunately this doesn't seem to work; I can't seem to get any window or window focus listeners to actually fire any methods, in fact?
    I hope that kind of makes sense lol. In short I'm looking for Notepad CTRL+R esque functionality, albeit with a modal box. As for a 'short' code listing:
    Main.java
    // Not all of these required for the code excerpt of course.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GraphicsEnvironment;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ComponentAdapter;
    import java.awt.event.ComponentEvent;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowFocusListener;
    import java.awt.event.WindowListener;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import javax.swing.UIManager;
    import javax.swing.plaf.basic.BasicSplitPaneDivider;
    import javax.swing.plaf.basic.BasicSplitPaneUI;
    public class Main extends JFrame implements ActionListener, WindowFocusListener, WindowListener, FocusListener {
         static JFrame frame;
         private static int programWidth;
         private static int programHeight;
         private static int minimumProgramWidth = 700;
         private static int minimumProgramHeight = 550;
         public static SetupProject setupProjectDialog;
         public Main() {
              // Setup the overall GUI of the program
         private static void createSetupProjectDialog() {
              // Now open the 'Setup Your Project' dialog box
              // !!! Naturally this wouldn't auto-open on load if the user has already created a project
              setupProjectDialog = new SetupProject( frame, "Create Your Website Project", true );
              // Okay, for this we want it to be (say) 70% of the progamWidth/height, OR *slightly* (-25px) smaller than the minimum size of 700/550
              // Change (base on programWidth/Height) then setLocation
              int currProgramWidth = getProgramWidth();
              int currProgramHeight = getProgramHeight();
              int possibleWidth = (int) (currProgramWidth * 0.7);
              int possibleHeight = (int) (currProgramHeight * 0.7);
              // Set the size and location of the JDialog as needed
              if( (possibleWidth > (minimumProgramWidth-25)) && (possibleHeight > (minimumProgramHeight-25)) ) {
                   setupProjectDialog.setPreferredSize( new Dimension(possibleWidth,possibleHeight) );
                   setupProjectDialog.setLocation( ((currProgramWidth/2)-(possibleWidth/2)), ((currProgramHeight/2)-(possibleHeight/2)) );
               else {
                   setupProjectDialog.setPreferredSize( new Dimension( (minimumProgramWidth-25), (minimumProgramHeight-25)) );
                   setupProjectDialog.setLocation( ((currProgramWidth/2)-((minimumProgramWidth-25)/2)), ((currProgramHeight/2)-((minimumProgramHeight-25)/2)) );
              setupProjectDialog.setResizable(false);
              setupProjectDialog.toFront();
              setupProjectDialog.pack();
              setupProjectDialog.setVisible(true);
         public static void main ( String[] args ) {
              Main frame = new Main();
              frame.pack();
              frame.setVisible(true);
              createSetupProjectDialog();
            // None of these get fired when the Jframe is switched to. I also tried a ComponentListener, but had no joy there either.
         public void windowGainedFocus(WindowEvent e) {
              System.out.println("Gained");
              setupProjectDialog.setVisible(true);
         public void windowLostFocus(WindowEvent e) {
              System.out.println("GainedLost");
         public void windowOpened(WindowEvent e) {
              System.out.println("YAY1!");
         public void windowClosing(WindowEvent e) {
              System.out.println("YAY2!");
         public void windowClosed(WindowEvent e) {
              System.out.println("YAY3!");
         public void windowIconified(WindowEvent e) {
              System.out.println("YAY4!");
         public void windowDeiconified(WindowEvent e) {
              System.out.println("YAY5!");
         public void windowActivated(WindowEvent e) {
              System.out.println("YAY6!");
         public void windowDeactivated(WindowEvent e) {
              System.out.println("YAY7!");
         public void focusGained(FocusEvent e) {
              System.out.println("YAY8!");
         public void focusLost(FocusEvent e) {
              System.out.println("YAY9!");
    SetupProject.java
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowFocusListener;
    import java.awt.event.WindowListener;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class SetupProject extends JDialog implements ActionListener {
         public SetupProject( final JFrame frame, String title, boolean modal ) {
              // Setup the JDialog
              super( frame, title, modal );
              setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
              // Bad code. Is only temporary
              add( new JLabel("This is a test.") );
              // !!! TESTING
              addWindowFocusListener( new WindowFocusListener() {
                   public void windowGainedFocus(WindowEvent e) {
                        // Naturally this now doesn't get called after the setVisible(false) call below
                   public void windowLostFocus(WindowEvent e) {
                        System.out.println("Lost");
                        setVisible(false); // Doing this sort of thing since frame.someMethod() always fires a null pointer exception?!
    }Any help would be very much greatly appreciated.
    Thanks!
    Tristan

    Hi,
    Many thanks for the reply. Isn't that what I'm doing with the super() call though?
    As in, in Main.java I'm doing:
    setupProjectDialog = new SetupProject( frame, "Create Your Website Project", true );Then the constructor in SetupProject is:
    public SetupProject( final JFrame frame, String title, boolean modal ) {
              // Setup the JDialog
              super( frame, title, modal );
              And isn't the super call (since the class extends JDialog) essentially like doing new JDialog(frame,title,modal)?
    If not, that would make sense due to the null pointer exception errors I've been getting. Although I did think I'd done it right hence am confused as to the right way to handle this,if so.
    Thanks,
    Tristan
    Edited by: 802573 on 20-Oct-2010 08:27

  • How can i only allow the activation of the JDialog on top?

    Hi to all,
    i have a problem with a mask swing
    Well, my problem is this:
    In a window, when i click on save button, it's open a customizing JDialog. But i would like how i can deny a click out of this JDialog, that is on top.
    In other words, in this situation, with a jdialog on top, if the user click once again on the save button or out of this jdialog, the jdialog must stay on top and active.
    How i can this?
    Please help me!!
    the code that realize my class is this:
    public class ConsegnaOrdineDialog extends JDialog implements ActionListener {
         private JOptionPane optionPane;
         private String dataOrdine;
         private JButton si, no;
         private JTextField dataConsegna;
         public ConsegnaOrdineDialog(String dataOrdine) {
              this.dataOrdine = dataOrdine;
              dataConsegna = new JTextField();
              si = new JButton("Si");
              no = new JButton("No");
              si.addActionListener(this);
              no.addActionListener(this);
              JPanel panel = new JPanel();
                 panel.setLayout(new BorderLayout(5, 10));
                 panel.add(dataConsegna, BorderLayout.NORTH);
                 panel.add(si, BorderLayout.WEST);
                 panel.add(no, BorderLayout.EAST);
              Object[] options = {panel};
              optionPane = new JOptionPane("La data �:",
                    JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.NO_OPTION,
                    null,
                    options,
                    dataConsegna);
              setContentPane(optionPane);
         public void actionPerformed(ActionEvent e) {
              if (e.getSource() == si) {
              if (e.getSource() == no) {
                   super.dispose();               
    }

    in the constructor
    setModal(true);

Maybe you are looking for