Jdialog and jframe

Hi.
I have a problem
I have a jdialog and when i click on a button i need open a jframe.
i do this but the jframe is not active or not enable.
Can you help me?
Thanks

Hi,
It should work, so please post some code

Similar Messages

  • Help with JDialog and JFrame

    I have a class that extends JDialog to display images in a slide show. I use the action performed method of a button in my main Jframe Application to start the slideshow .
    When the button is clicked the JDialog opens multiple windows and the images arent displayed properly at all . But when I tested the slideshow of Jdialog separately , it works.
    Here is the code of the Jdialog part
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    public class Test extends JDialog implements ActionListener
    {  private Image img; 
    private     JMenuBar     menuBar;
    private     JMenu          menuStart;
    public Vector images = new Vector();
    public Test()
    for (int i = 1; i < 8; i++)
    {      images.add(new ImageIcon("gty"+i+".jpg").getImage());  
    menuBar = new JMenuBar();
         setJMenuBar( menuBar );
         menuStart = new JMenu( "Start" );
         menuStart.setMnemonic( 'S' );
         menuStart.addActionListener(this);
         menuBar.add( menuStart );
    setSize(600, 600);
    setVisible(true);
    showImages(images);
    private void showImages(Vector images) {
    for (int i = 1; i < images.size(); i++)
    img = (Image) (images.elementAt(i));
    int imgWidth = img.getWidth(this);
    int imgHeight = img.getHeight(this);
    setSize( imgWidth, imgHeight );
    JLabel temp=new JLabel(new ImageIcon(img));
    this.getContentPane().add(temp);
    pack();
    setVisible(true);
    try { Thread.sleep(2000);
    } catch (Exception e) {} //do nothing
    getContentPane().remove(temp);
    pack();
    setVisible(true);
    public void actionPerformed( ActionEvent event )
    public static void main(String[] arghs)
    {//new Test(null,true);
    In the main application I just gave created an object of this type test
    i.e new Test();
    I have tried changing the constructor of the Jdialog to include parent frame and modal , but it still dosen't work . Help !

    when you declare the final variables, it should be initialized otherwise you will get error
    private final JTabbedPane tabbedPane; //not assigned yet should be
    private final JTabbedPane tabbedPane = new JTabbedPane()

  • Difference between Jdialog and JFrame

    though i know one difference of these two top-level containers such that, Jdialog dont have the iconifying buttons like JFrame.I would like to know whether they have any other differences.If they have,please list out them.

    There is a subtle difference between these components. JFrame is a fully-functional Windows window, where as JDialog is a popup-sort-of window. That sounds pretty weak. Essentially, you should use a JFrame for the part of your program that is always visible (unless it's minimized), while JDialog's pop up when you need them, and disapear when you don't.

  • Communicating between JDialog and JFrame

    Hi,
    Here's the scenario...
    1. Application creates a JFrame MainScreen (this is the 'main' screen) - with a JTabbedPane
    2. User clicks New Project JButton
    3. Application create an instance of NewProject class (separate from the MainScreen) class - which extends JDialog
    4. User completes necessary detail (project name etc)
    5. User clicks Finish
    6. Dialog closes, a new tab is created in the JFrame
    I have got to number 6, but am confused as to how I can communicate with the JFrame's JTabbedPane to say 'User has clicked finish, here are the details of the project, create a new instance of the ProjectTab class and add it to the JTabbedPane.
    Please help!!!!!!!
    Many Thanks,
    John

    There's a number of ways:
    1) Pass a reference to the MainScreen to the NewProject dialog. Provide a method in MainScreen to add the project to the MainScreen when the dialog is finished. When the user accepts the new project have the NewProject dialog add it to the MainScreen using the aforementioned method. This method would in turn add something to the JTabbedPane.
    2) Make the dialog modal and have it return a value indicating the users action. The MainScreen would launch the dialog and get back a value indicating the users action. If the user accepted the MainScreen would ask the NewProject dialog for whatever it needs to add it to the MainScreen.

  • 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.

  • Dynamic resize of JButton and JFrame in response to Font

    Im supposed to increase the font size of the text with JButton by 1 within each click.
    Eventually the text becomes shorter and less visible like WORD becomes WOR... then WO... etc
    How to make the button always resize with text so that the text is fully visible and JFrame always resize with button so that the button doesn't change its position within the Frame ?
    edit:
    I managed to make buttons resize with increasing font
    by making
    JButton b = new JButton("button");
    b.setHorizontalTextPosition(CENTER);
    b.setVerticalTextPosition(CENTER);However the window size doesnt increase with components ;[
    any help would be appretiated.
    Edited by: pimpcane on Dec 11, 2007 12:16 PM

    Ok I managed to get it working moreless by
    adding pack() to the actionPerformed(...) function
    public void actionPerformed(ActionEvent e)
                 int index = Integer.parseInt(e.getActionCommand());
              int size = buttons[index].getFont().getSize();
              size++;
              buttons[index].setFont(new Font(name, style, size));
              pack();
    }The problem is in the task im given it is forbidden to use pack();
    Is there any other method to obtain the same result of JFrame resizing dynamically in response to components resize ?
    Edited by: pimpcane on Dec 12, 2007 12:13 PM
    Edited by: pimpcane on Dec 12, 2007 12:15 PM

  • How to  pass data between JDialog and its parent window ?

    Hi,
    I am new to swing. I want to know how pass data between a JDialog and its parent window.
    If you have any information please reply with example code.
    Thank You

    hi Encephalopathic ,
    I was looking for something like as it was given in the link provided by you.
    Thank you for reply It really helped me.

  • Difference Frame and JFrame

    can somebody help me to explain the difference between Frame and JFrame OR maybe you can put a link of (java.sun.com) so that i may understand it!
    thanx!

    Start here,
    [url http://java.sun.com/docs/books/tutorial/uiswing/start/swingIntro.html#awt]How Are Swing Components Different from AWT Components?
    continue with [url http://java.sun.com/docs/books/tutorial/uiswing/converting/index.html]Converting to Swing

  • Java Communication Between Classes and JFrame JDialog

    i have written a standalone connect 4 game.
    next i would like to be able to play it over network and also have a chat function.
    connect 4 GUI (JFrame) holds -> connect 4 game model
    i would like to implement connect 4 network GUI(JDialog) (here the user can choose to act as a server or client) that holds Network API.
    and finally a Chat GUI (JDialog) to exchange messages.
    my question is how do i implement inter class/GUI communication? when a network message is received it ought to be delivered to the right receiver (game / chat) also messages sent from chat / game transmitted to remote machine.
    i have looked into inner classes but was told it is a bad idea to implement so much with in single class and i did not like this idea a lot either.
    i have written another game battleships in C# and it uses delegates to accomplish this task but sadly im informed that delegates are not available in Java.
    im a beginner and at the moment exploring options so im open to your guidance.
    thank you.

    Addition to my above submission
    To clarify, I'll offer the US$20 to the FIRST person who offers me a workable solution to the problem, not to everyone!!!
    JMGRAHAM

  • Never used JWindow&JDialog and was very happy

    Hi guys!
    I am stuck on simple task. I wanted to place my jpanel into jwin or jdialog so this panel could resize and be dragged inside the JFrame. It would look very neat. Of course I don't want the stupid title bar.
    JWindow turned out to be not resizable and non-movable. Well, I saw people put mouse listeners on it but it does not solve resizability problem.
    JDialog (1.4 jdk) when undecorated is also not resizable (.setResizable(true))and not movable.
    Do you have any idea how to accomplish this task? Will be very grateful.

    I did my best and got almost what I wanted. Some things depend on their native implementations. Nothing I could do.
    I think that JWindows and JDialog are very tricky and devious components. One should stay away from them as far as possible because it's very difficult to make them do what you want: be simple, draggable, freely resizable and stay on top of their owner.

  • JDialog and modality

    Hello,
    I'm wondering if my thinking is correct. If you create a jDialog box like this: JOptionPane.showMessageDialog(null, "some message here."); It's modal but since there is no parent frame it act non modal?
    And if you create it like this, JOptionPane.showMessageDialog(frame, "some message here."); Actually specifying the parent, it will act modal?
    Thank You!

    Hello,
    I see in the java tutorials it says "+A Dialog can be modal. When a modal Dialog is visible, it blocks user input to all other windows in the program. JOptionPane creates JDialogs that are modal. To create a non-modal Dialog, you must use the JDialog class directly.+" I'm using JOptionPane in both my test cases.
    I'm using the most basic test case I can think of:
    public class MyTestingApp {
        public static void main(String[] args) {
            JFrame frame = new JFrame("FrameDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
            JOptionPane.showMessageDialog(null, "My message.");
    }I cannot reproduce the problem, it always behaves modal as camickr expected. Only thing is, in my real application the dialog box appears underneath the main application window on rare occasion. I've seen it happen once in the field. I've also seen examples online where the word keyword this+ (referring to the parent objects name) was used instead of null or using the parent frame name. It doesn't seem to matter which is used, in the documentation or an application.
    Thanks,
    Sc

  • Inability to draw simple graphics in Java properly (threads and JFrame)

    I am trying to use a thread to continually draw randomly positioned and randomly sized squares in the middle of a JFrame window. I have got 'something' working with the following code, however when run, the actual window doesn't come up properly. If I resize the window it does, and I get the result I wanted, but when the window is first opened it does not fully draw itself on screen. Can anybody help here? I am a bit of a novice when it comes to Java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class TestDraw extends JFrame implements Runnable {
    //DECLARE VARIABLES
         private JLabel lblText;
         private JButton btnBegin;
         private JPanel contentPane;
         private int CoordX, CoordY,SizeX, SizeY, Colour;     // Co'ords for drawing the squares
         Random random = new Random();                              // Random numbers (for square dimensions and colours)
         int n_1 = 450, n_2 = 130, n_3 = 100, n_4 = 4;          // The different ranges of randoms I require
         Thread squares = new Thread(this);                         // Implements a new thread
    //END OF DECLARE VARIABLES
    // CALLS INITIAL PROCEDURE, SETS VISIBLE ETC
         public TestDraw() {
              super();
              initializeComponent();
              this.setVisible(true);
    // INITIALISATION PROCEDURE CALL
         private void initializeComponent() {
              lblText = new JLabel();
              btnBegin = new JButton();
              contentPane = (JPanel)this.getContentPane();
              // lblText
              lblText.setText("This should draw squares on screen...");
              // btnBegin
              btnBegin.setText("Start");
              btnBegin.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        btnBegin_actionPerformed(e);
              // contentPane
              contentPane.setLayout(null);
              addComponent(contentPane, lblText, 10,300,364,18);
              addComponent(contentPane, btnBegin, 144,10,101,28);
              // TestDraw
              this.setTitle("TestDraw Program for CM0246");
              this.setLocation(new Point(0, 0));
              this.setSize(new Dimension(390, 350));
    // POSITION COMPONENTS ON SCREEN
         private void addComponent(Container container,Component c,int x,int y,int width,int height)     {
              c.setBounds(x,y,width,height);
              container.add(c);
    // EVENT HANDLING PROCEDURES
         private void btnBegin_actionPerformed(ActionEvent e) {
              System.out.println("\nAction Event from btnBegin called...");
              squares.start(); //STARTS THE SQUARES DRAWING THREAD (Draws random squares on screen)
    // THE MAIN METHOD (STARTS THE PROGRAM)
         public static void main(String[] args) {
              TestDraw bobdole = new TestDraw();
    // THE SQUARE DRAWINGS THREAD (SHOULD DRAW RANDOM SIZED AND COLOURED SQUARES IN RANDOM PLACES)
         public void run() {
              System.out.println("Thread running if this prints");
                   while(true) {
                        int int_1 = random.nextInt(n_1);     // chooses random int for X co'ord
                        int int_2 = random.nextInt(n_2)+70;     // chooses random int for Y co'ord
                        int int_3 = random.nextInt(n_3)+10;     // chooses random int for X dimension
                        int int_4 = random.nextInt(n_3)+10;     // chooses random int for Y dimension
                        CoordX = int_1;
                        CoordY = int_2;
                        SizeX  = int_3;
                        SizeY  = int_4;
                        repaint();
                        try {
                             squares.sleep(500);
                        catch (InterruptedException e) {
                             System.out.println(e);
    // THE PAINT METHOD ATTATCHED TO THE SQUARES THREAD
         public void paint( Graphics g ) {
              System.out.print("Colour" + Colour);
              g.setColor(Color.blue);
              g.fillRect(CoordX, CoordY, SizeX, SizeY);
    // END OF PROGRAM

    I don't see any problem when I run the program but.. In general you shouldn't paint directly on a frame by overloading the paint method. You should rather create a custom component on which you draw.
    But if you do overload paint, make sure you call super.paint before doing anything else.
    More information in this tutorial: http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html

  • Problem with ScrollPane and JFrame Size

    Hi,
    The code is workin but after change the size of frame it works CORRECTLY.Please help me why this frame is small an scrollpane doesn't show at the beginning.
    Here is the code:
    import java.awt.*;
    public class canvasExp extends Canvas
         private static final long serialVersionUID = 1L;
         ImageLoader map=new ImageLoader();
        Image img = map.GetImg();
        int h, w;               // the height and width of this canvas
         public void update(Graphics g)
            paint(g);
        public void paint(Graphics g)
                if(img != null)
                     h = getSize().height;
                     System.out.println("h:"+h);
                      w = getSize().width;
                      System.out.println("w:"+w);
                      g.drawRect(0,0, w-1, h-1);     // Draw border
                  //  System.out.println("Size= "+this.getSize());
                     g.drawImage(img, 0,0,this.getWidth(),this.getHeight(), this);
                    int width = img.getWidth(this);
                    //System.out.println("W: "+width);
                    int height = img.getHeight(this);
                    //System.out.println("H: "+height);
                    if(width != -1 && width != getWidth())
                        setSize(width, getHeight());
                    if(height != -1 && height != getHeight())
                        setSize(getWidth(), height);
    }I create frame here...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JFrame;
    public class frame extends JFrame implements MouseMotionListener,MouseListener
         private static final long serialVersionUID = 1L;
        private ScrollPane scrollPane;
        private int dragStartX;
        private int dragStartY;
        private int lastX;
        private int lastY;
        int cordX;
        int cordY;
        canvasExp canvas;
        public frame()
            super("test");
            canvas = new canvasExp();
            canvas.addMouseListener(this);
            canvas.addMouseMotionListener(this);
            scrollPane = new ScrollPane();
            scrollPane.setEnabled(true);
            scrollPane.add(canvas);
            add(scrollPane);
            setSize(300,300);
            pack();
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void mousePressed(MouseEvent e)
            dragStartX = e.getX();
            dragStartY = e.getY();
            lastX = getX();
            lastY = getY();
        public void mouseReleased(MouseEvent mouseevent)
        public void mouseClicked(MouseEvent e)
            cordX = e.getX();
            cordY = e.getY();
            System.out.println((new StringBuilder()).append(cordX).append(",").append(cordY).toString());
        public void mouseEntered(MouseEvent mouseevent)
        public void mouseExited(MouseEvent mouseevent)
        public void mouseMoved(MouseEvent mouseevent)
        public void mouseDragged(MouseEvent e)
            if(e.getX() != lastX || e.getY() != lastY)
                Point p = scrollPane.getScrollPosition();
                p.translate(dragStartX - e.getX(), dragStartY - e.getY());
                scrollPane.setScrollPosition(p);
    }...and call here
    public class main {
         public main(){}
         public static void main (String args[])
             frame f = new frame();
    }There is something I couldn't see here.By the way ImageLoader is workin I get the image.
    Thank you for your help,please answer me....

    I'm not going to even attempt to resolve the problem posted. There are other problems with your code that should take priority.
    -- class names by convention start with a capital letter.
    -- don't use the name of a common class from the standard API for your custom class, not even with a difference of case. It'll come back to bite you.
    -- don't mix awt and Swing components in the same GUI. Change your class that extends Canvas to extend JPanel instead, and override paintComponent(...) instead of paint(...).
    -- launch your GUI on the EDT by wrapping it in a SwingUtilities.invokeLater or EventQueue.invokeLater.
    -- calling setSize(...) followed by pack() is meaningless. Use one or the other.
    -- That's not the correct way to display a component in a scroll pane.
    Ah, well, and the problem is that when you call pack(), it retrieves the preferredSize of the components in the JFrame, and you haven't set a preferredSize for the scroll pane.
    Please, for your own good, take a break from whatever it is you're working on and go through The Java&#8482; Tutorials: [Creating a GUI with JFC/Swing|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html]
    db

  • Problem with Background image and JFrame

    Hi there!
    I've the following problem:
    I created a JFrame with an integrated JPanel. In this JFrame I display a background image. Therefore I've used my own contentPane:
    public class MContentPane extends JComponent{
    private Image backgroundImage = null;
    public MContentPane() {
    super();
    * Returns the background image
    * @return Background image
    public Image getBackgroundImage() {
    return backgroundImage;
    * Sets the background image
    * @param backgroundImage Background image
    public void setBackgroundImage(Image backgroundImage) {
    this.backgroundImage = backgroundImage;
    * Overrides the painting to display a background image
    protected void paintComponent(Graphics g) {
    if (isOpaque()) {
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    if (backgroundImage != null) {
    g.drawImage(backgroundImage,0,0,this);
    super.paintComponent(g);
    Now the background image displays correct. But as soon as I click on some combobox that is placed within the integrated JPanel I see fractals of the opened combobox on the background. When I minimize
    the Frame they disappear. Sometimes though I get also some fractals when resizing the JFrame.
    It seems there is some problem with the redrawing of the background e.g. it doesn't get redrawn as often as it should be!?
    Could anyone give me some hint, on how to achieve a clear background after clicking some combobox?
    Thx in advance

    I still prefer using a border to draw a background image:
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.border.*;
    public class CentredBackgroundBorder implements Border {
        private final BufferedImage image;
        public CentredBackgroundBorder(BufferedImage image) {
            this.image = image;
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            int x0 = x + (width-image.getWidth())/2;
            int y0 = y + (height-image.getHeight())/2;
            g. drawImage(image, x0, y0, null);
        public Insets getBorderInsets(Component c) {
            return new Insets(0,0,0,0);
        public boolean isBorderOpaque() {
            return true;
    }And here is a demo where I load the background image asynchronously, so that I can launch the GUI before the image is done loading. Warning: you may find the image disturbing...
    import java.awt.*;
    import java.io.*;
    import java.net.URL;
    import javax.imageio.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class BackgroundBorderExample {
        public static void main(String[] args) throws IOException {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame f = new JFrame("BackgroundBorderExample");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JTextArea area = new JTextArea(24,80);
            area.setForeground(Color.WHITE);
            area.setOpaque(false);
            area.read(new FileReader(new File("BackgroundBorderExample.java")), null);
            final JScrollPane sp = new JScrollPane(area);
            sp.setBackground(Color.BLACK);
            sp.getViewport().setOpaque(false);
            f.getContentPane().add(sp);
            f.setSize(600,400);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            String url = "http://today.java.net/jag/bio/JagHeadshot.jpg";
            final Border bkgrnd = new CentredBackgroundBorder(ImageIO.read(new URL(url)));
            Runnable r = new Runnable() {
                public void run() {
                    sp.setViewportBorder(bkgrnd);
                    sp.repaint();
            SwingUtilities.invokeLater(r);
    }

  • Problem: modal JDialog and keyListeners

    I have some code like this:
    MyDialog extends JDialog {
    MyDialog () {
    super(someFrame, "", false);
    add(someComponent);
    someComponent.addKeyListener(listener);
    listener receives events just as I expect. Now I need to make a modal dialog and change false to true. in this case listener don't receive any events. Why? What is wrong and how should I fix it?
    However, if I create non-modal dialog, add key listener and use setModal(true) after, everything seems to work just fine. Maybe it's just a bug in java?

    Finally, I figured out the reason. Here is the code:
    class MyDialog extends JDialog {
    MyDialog() {
    super(someFrame, "", true);
    // GUI initialisation
    pack();
    someComponent.addKeyListener(listener);
    setVisible(true);
    In this case, listener receives events. But if I add listener AFTER setVisible, it does receive nothing. In case of non-modal dialog, listener receives events in both cases.

Maybe you are looking for

  • Display Rows as Columns

    Hi, Can anyone help, I have some rows that I am trying to display as columns. The sample data is below: create table c( ID NUMBER, SCHEDULE_NO NUMBER, TERM_NO NUMBER, FREQUENCY VARCHAR2(20), RENTAL_AMOUNT NUMBER, RENTAL_OS NUMBER); INSERT INTO C VALU

  • DefaultCellEditor in JTable can not update itself when the value changes

    Hi, I have a JTable which has 4 columns. The 3rd column has a comboBox. whenever I select an item from the first row, the cell at (currentrow, 4thcolumn) will be updated according to the item selected. Now the problem is, after selecting the item in

  • Upload LIFA_Base error

    Hi I'm working with arduino for the first time and I ran into a problem on the very first steps. I did connect my arduino mega 2560 with my pc. I checked out NI max and it shows under devices. Next I did open the LIFA_Base.ino file located at c:\prog

  • Trying to update Photoshop 5 Camera Raw. Get message installation failed. No other information. Please advise.

    Trying to update Photoshop 5 Camera Raw. Get message installation failed. No other information. Please advise. Running Windows 7 64 bit on Dell Precision m4500. 8G 500G. Is there an alternative way to update the camera profiles in ACR. I am trying to

  • NO SERVICE on 2.0.1 update....

    No idea what to do now.... Im in Portugal and was given the option to update my 3G Iphone to 2.0.1 and as soon as it finished the update... NO SERVICE... i cannot make any calls whatsoever... i can use the rest of the phone like a ipod touch... but c