Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Jframe Pop outs when clicking JButton

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Exclamation Jframe Pop outs when clicking JButton

    i'm working on a project but now i'm stuck, i'm trying to make i where if i press the options button another Jframe will pop out, i want this other Jframe to contain options/buttons/etc is there anyway to do this, and would like to only use JFrames for this project. can someone help me/get me in the right direction on how to make this, i have no idea how to add muti Jframes, I've tryed odds and ends and nothing worked.

    private JButton sendButton;

    			sendButton = new JButton("    Send    ");
    			add( sendButton );
    			sendButton.addActionListener(new ActionListener() {
    				public void actionPerformed(ActionEvent event) {


    Main JFrame-
    import javax.swing.JFrame;
     
    public class MessageBoxCreator {
    	public static void main(String[] args){
     
    		MainClass creationFrame = new MainClass();
    		creationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		creationFrame.setSize(625,415);
    		creationFrame.setVisible(true);
    		creationFrame.setResizable(false);
    	}
     
    }


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Jframe Pop outs when clicking JButton

    If you plan on going back to the window you navigate from, setVisible(boolean b) to false, and in the actionPerformed, set the new JFrame visible.
    If you will don't plan on going back to the navigation frame, call dispose() and set the new JFrame to visible.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jframe Pop outs when clicking JButton

    okay i understand that, but where do i make the the JFrame?

  4. #4
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jframe Pop outs when clicking JButton

    as of a new .java or what

  5. #5
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Jframe Pop outs when clicking JButton

    If you want, you're only setting a JFrame object visible, so It can be a blank JFrame or your own subclass of it.
    Really isn't any different to how you will have used JFrame's in the past
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  6. The Following User Says Thank You to newbie For This Useful Post:

    Java Programmer (January 22nd, 2012)

  7. #6
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jframe Pop outs when clicking JButton

    Thanks!

    					JFrame options = new JFrame("options");
    					options.setVisible(true);
    					options.setSize(200,200);

  8. #7
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Jframe Pop outs when clicking JButton

    For future reference, always have setVisible as the last command issued when dealing with frames.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  9. #8
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Jframe Pop outs when clicking JButton

    lol, thanks for the info but when adding things to the new jframe, do i just put it under the jframe or like call it? ex: options.sdsd = new label

Similar Threads

  1. help with JButton closing a JFrame :)
    By skerridge in forum AWT / Java Swing
    Replies: 15
    Last Post: January 16th, 2012, 12:11 AM
  2. Im trying to open a new GUI window by clicking on a button
    By amzwans in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 10th, 2011, 11:33 PM
  3. Double Clicking JAR files
    By bgroenks96 in forum Java Theory & Questions
    Replies: 1
    Last Post: June 14th, 2011, 06:53 AM
  4. java is not clicking for me, why?
    By cejay in forum Java Theory & Questions
    Replies: 1
    Last Post: February 28th, 2010, 11:57 AM
  5. how to make a simple JButton on a JFrame window?
    By chronoz13 in forum AWT / Java Swing
    Replies: 8
    Last Post: November 20th, 2009, 09:08 PM