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 3 of 3

Thread: Blank JFrame

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Blank JFrame

    Hey guys,

    I am having a problem with my code as it displays a blank JFrame to me whereas it should display a button.

    The initialization code stands as follows:
                    JFrame frame = new JFrame();
    		Canvas canvas = new Canvas();
    		canvas.setSize(WIDTH, HEIGHT);
    		frame.setResizable(false);
    		frame.addWindowFocusListener(new WindowAdapter() {
    			@Override
    			public void windowGainedFocus(WindowEvent e) {
    				canvas.requestFocusInWindow();
    			}
    		});
    		frame.addWindowListener(new WindowAdapter() {
    			@Override
    			public void windowClosing(WindowEvent e) {
    				closeRequested = true;
    			}
    		});
    		frame.add(canvas);
                    try {
    			Display.setParent(canvas);
    			Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
     
    			frame.pack();
    			frame.setVisible(true);
     
    			Display.create();
    		} catch (LWJGLException e) {
    			e.printStackTrace();
    		}

    The above code creates the JFrame as well as the LWJGL display.

    At some point during the program, the following method is called:

                    public void craft(){
    			JButton button = new JButton("Exit");
    	        button.addActionListener(new ActionListener() {
    	            public void actionPerformed(ActionEvent event) {
    	                STATE = GAME;
    	                remove();
    	                frame.getRootPane().revalidate();
    	            }
    	        });
    	        frame.add(button);
    			frame.getRootPane().revalidate();
    		}

    AS a result nothing is displayed on the JFrame.

    I have tested that the method does in fact run and has no errors in completing it, as well as altered the frame.getRootPane().revalidate(); to frame.revalidate(); with no success.
    The only success I have had was due to me changing the frame.add(button); to frame.add(button, BlockLayout.Center); which results in the buttons filling the screen, I am not sure where to proceed from here in terms of getting this to work.

    Anyone have any ideas?

    Thanks

    SACoder


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Blank JFrame

    Can you post a small complete program that compiles, executes and shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Blank JFrame

    Can you post source code ?

Similar Threads

  1. [SOLVED] the output is just a blank frame... no menu bar is present.. plz help me out..
    By namita in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 19th, 2012, 01:08 PM
  2. Blank JFrame
    By SACoder in forum AWT / Java Swing
    Replies: 0
    Last Post: July 11th, 2012, 11:10 AM
  3. Java dialog box is blank in 2nd attempt while using timer.
    By mocherla81 in forum AWT / Java Swing
    Replies: 1
    Last Post: January 17th, 2011, 08:49 AM
  4. url input stream returning blank
    By yo99 in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: June 2nd, 2010, 08:14 PM
  5. Making a little Lua script 'generator', JFrame showing up blank.
    By scribbleno1 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 2nd, 2010, 07:00 PM

Tags for this Thread