Results 1 to 3 of 3
  1. #1
    batia is offline Member
    Join Date
    Feb 2011
    Location
    Lithuania
    Posts
    16
    Rep Power
    0

    Default Frame and DialogBox

    Hello,

    My problem is.
    I have a frame, and a dialog box.
    When i push a button. A dialog box shows.
    Problem is, that i can navigate to frame aggain.
    I want to make, that i could not return to my frame until i have done with dialog Box. It' is like situation when opening file. Until open dialog box is not closed you can not return to program.

    ImportChooserDialogFrame

    Java Code:
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    
    
    public class ImportChooserDialogFrame extends JDialog{
    	
    	int choose = 0;
    	
    	ImportChooserDialogFrame(JFrame frame, String fileName){
    		super(frame,"choose import type..");
    		ImportChooserDialogPanel importChooserDialogPanel = new ImportChooserDialogPanel(fileName);
    		setContentPane(importChooserDialogPanel);
    		importChooserDialogPanel.ancestorFrame = this;
    		
    		setSize(250,150);
    		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    		setLocation(500,500);
    		setVisible(true);
    		setResizable(false);
    	}
    	public static void main(String[] args) {
    		JFrame myFrame = new JFrame("");
    		myFrame.setSize(400,400);
    		myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		myFrame.setVisible(true);
    		ImportChooserDialogFrame importChooser = new ImportChooserDialogFrame(myFrame,"c:/test/test.txt");
    		
    	}
    }
    ImportChooserDialogPanel

    Java Code:
    import static javax.swing.GroupLayout.Alignment.LEADING;
    
    import java.awt.Container;
    
    import javax.swing.ButtonGroup;
    import javax.swing.GroupLayout;
    import javax.swing.JButton;
    import javax.swing.JRadioButton;
    import javax.swing.JTextField;
    
    
    public class ImportChooserDialogPanel extends Container {
    
    	String [] radioButtonNames = {"nobs and frequency","nobs and probability"};
    	JRadioButton[] selector ;
    	final JButton okButton = new JButton("ok");
    	final JButton cancelButton = new JButton("cancel");
    	final JTextField fileNameField = new JTextField ();
    	ImportChooserDialogFrame ancestorFrame;
    	
    	ImportChooserDialogPanel(String fileName){
    		super();
    
    		GroupLayout layout = new GroupLayout(this);
    		setLayout(layout);
    		layout.setAutoCreateGaps(true);
    	    layout.setAutoCreateContainerGaps(true);
    	    fileNameField.setText(fileName);
    	    fileNameField.setEditable(false);
    	    
    	    ButtonGroup selectorGroup = new ButtonGroup ();
    		selector = new JRadioButton[radioButtonNames.length];
    		for (int i = 0;i<selector.length; i++){
    			selector[i] = new JRadioButton(radioButtonNames[i], i==0 );
    			selectorGroup.add(selector[i]);
    		}
    		
    		layout.setHorizontalGroup(layout.createParallelGroup(LEADING)
    				.addComponent(selector[0])
    				.addComponent(selector[1])
    				.addGroup(layout.createSequentialGroup()
    					.addGap(30)
    					.addComponent(okButton,80,80,80)
    					.addComponent(cancelButton,80,80,80))
    				.addComponent(fileNameField)
    			);
    		layout.setVerticalGroup(layout.createSequentialGroup()
    			.addComponent(selector[0])
    			.addComponent(selector[1])
    			.addGap(20)
    			.addGroup(layout.createParallelGroup(LEADING)
    				.addComponent(okButton,20,20,20)
    				.addComponent(cancelButton,20,20,20)
    			)
    			.addGap(5)
    			.addComponent(fileNameField)
    		);
    	}		
    }
    Thanks in advance.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Frame and DialogBox

    You need to set the modality of the dialog before setting it visible. One of the easiest ways to do this is to use a constructor of JDialog that does this for you. In other words, don't use super(), but a different super constructor. Or if you choose there are JDialog methods that can do this as well. The JDialog API can help you with this.

  3. #3
    batia is offline Member
    Join Date
    Feb 2011
    Location
    Lithuania
    Posts
    16
    Rep Power
    0

    Default Re: Frame and DialogBox

    Thanks. That helped.

    By the way, how to mark this thread "solved"? Is this forum functionality still available?

Similar Threads

  1. Replies: 4
    Last Post: 01-18-2011, 09:22 AM
  2. Java slave Frame access to its owner main frame problem
    By cagdaseckin in forum New To Java
    Replies: 0
    Last Post: 12-10-2010, 11:40 AM
  3. SWing;* ISsue dial dialogbox
    By eppoair2 in forum AWT / Swing
    Replies: 3
    Last Post: 11-29-2010, 11:52 PM
  4. Replies: 7
    Last Post: 11-02-2009, 07:31 PM
  5. [SOLVED] swing dialogbox size
    By MK12 in forum New To Java
    Replies: 26
    Last Post: 02-13-2009, 06:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •