Results 1 to 8 of 8
  1. #1
    Willi's Avatar
    Willi is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Default JTextArea in Full-Screen Exclusive Mode

    Can we put a JTextArea in a frame to display in Fullscreen Exlcusive mode. I tried and the result is depressed.

    If I put these lines of code in my program, the full-screen exclusive mode is not showed up :

    Java Code:
    		JTextArea textArea = new JTextArea(20, 30);
    		textArea.setLineWrap(true);
    		textArea.setEditable(false);
    		
    		JScrollPane scrollPane = new JScrollPane(textArea);
    
                    JPanel panel = new JPanel();
                    panel.add(scrollPane);
    But then I removed it and the full-screen mode is showed up properly. Is there any idea about this problem?

    If JTextArea is the problem then is there a way to put multiple lines text on a JFrame in Fullscreen Exclusive mode?

    Thanks in advance!
    Write a program to achieve anything you want in your life!

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

    Default

    Perhaps I'm missing something (which happens too often), but I don't see anything in that code that would prevent full-screen mode from working. You may wish to create and post a small workable program that compiles, runs, requires no external resources, and which demonstrates your problem (an SSCCE), and let us play with it. Much luck.

  3. #3
    Willi's Avatar
    Willi is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Default

    Thanks for replying. Here is the code, I hope you can spend a little time to look through. The program is long, but it's straightforward :

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    public class FullScreenTest
    {
    	public static void main(String[] args)
    	{
    		EventQueue.invokeLater(new Runnable()
    		{
    			public void run()
    			{
    				GraphicsEnvironment en = GraphicsEnvironment.getLocalGraphicsEnvironment();
    				GraphicsDevice[] devices = en.getScreenDevices();
    				
    				for (int i = 0; i < devices.length ; i++)
    				{
    					FullScreenFrame frame = new FullScreenFrame(devices[i]);
    					frame.enterFullScreen();
    						    }										
    				}
    			});
    	}
    }
    
    class FullScreenFrame extends JFrame
    {
    	private GraphicsDevice graphicsDevice;
    	private DisplayMode originalMode;
    
    	private JPanel northPanel;
    	private JPanel southPanel;
    	private JTextArea textArea;
    	private JButton exitButton;
    	
    	public FullScreenFrame(final GraphicsDevice graphicsDevice) 
    	{
    		this.graphicsDevice = graphicsDevice;
    		
    		// save the original display mode for restoring to original mode purpose
    		originalMode = graphicsDevice.getDisplayMode();
    	
    		// this panel is used to hold the JTextArea
    		northPanel = new JPanel();
    		
    		// create a text area to hold text
    		textArea = new JTextArea(20, 30);
    		textArea.setLineWrap(true);		
    		textArea.setEditable(false);
    		
    		JScrollPane scrollPane = new JScrollPane(textArea);
    		northPanel.add(scrollPane);
    	
    		// a JButton to exit the fullscreen exclusive mode
    		exitButton = new JButton("Exit");
    		southPanel = new JPanel();
    		southPanel.add(exitButton);
    	
    		add(northPanel, BorderLayout.NORTH);
    		add(southPanel, BorderLayout.SOUTH);
            
    		// Register an ActionListener for the exitButton
    		exitButton.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent event)
    			{
    				// Restore the original display mode
    				graphicsDevice.setDisplayMode(originalMode);
    				graphicsDevice.setFullScreenWindow(null);
    				
    				// Exit the application
    				System.exit(0);
    			}
    		}); 
    	}
    
    	
    	// Method to enter the fullscreen exclusive mode
    	public void enterFullScreen()
    	{
    		// Check whether the full-screen exclusive mode is supported on this system
    		if(graphicsDevice.isFullScreenSupported())
    		{
    			setUndecorated(true);
    			setResizable(false);
    			setIgnoreRepaint(true);
    			
    			graphicsDevice.setFullScreenWindow(this);
    			validate();
    		}
    		else
    		{
    			// If the full-screen exclusive mode is not supported, show a dialog box to prompt a message
    			JOptionPane.showMessageDialog(null, "Full-Screen Exclusive Mode is not supported!");
    		}
    	}
    }
    Write a program to achieve anything you want in your life!

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

    Default

    I compiled your code, and on my computer (windows xp, java 1.6), full-screen mode appeared to work just fine with or without adding the JTextArea / JScrollPane. So I have no idea what is the cause of your problem. Could it be an OS or hardware dependent issue? Have you searched the Java bug database?

    Much luck

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    and on my computer (windows xp, java 1.6),
    I use the same configuration. (build 1.6.0_07-b06) and I also have problems. When I run the code with the following line comment out I get full screen mode:

    // northPanel.add(scrollPane);

    When the line is uncommented, I don't get full screen mode (nothing is displayed) and my computer freezes up.

    I have this old code I found on the web lying around. I can display a text area using this code, however, the text area cannot accept input. Seems to me its like the problem of using a JWindow, that can't accept focus unless it was created specifying a parent JFrame.

    I have no idea what the solution is, but here is the other code which seems to work a little better (for me anyway):

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    
    public class FullScreen01 extends JFrame
                                     implements ActionListener{
    
      private GraphicsDevice graphicsDevice;
      private DisplayMode origDisplayMode;
      private JButton exitButton = new JButton(
                                      "Exit Full-Screen Mode");
    
      public static void main(String[] args){
        //Get and display a list of graphics devices solely for
        // information purposes.
        GraphicsEnvironment graphicsEnvironment =
             GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = 
                        graphicsEnvironment.getScreenDevices();
        for(int cnt = 0;cnt < 1;cnt++){
          System.out.println(devices[cnt]);
        }//end for loop
    
        //Construct a full-screen object using
        // graphicsDevice 0.
        new FullScreen01(devices[0]);
      }//end main
    
      //Constructor
      public FullScreen01(GraphicsDevice graphicsDevice){
        //Save a reference to the graphics device as an
        // instance variable so that it can be used later to
        // exit the full-screen mode.
        this.graphicsDevice = graphicsDevice;
    
        setTitle("This title will be hidden (undecorated)");
    
        //Get and save a reference to the original display
        // mode as an instance variable so that it can be
        // restored later.
        origDisplayMode = graphicsDevice.getDisplayMode();
    
        //Register an action listener on the exitButton.
        exitButton.addActionListener(this);
    
        //Place the exitButton in the JFrame
        getContentPane().add(exitButton, BorderLayout.NORTH);
    
        //Place four labels in the JFrame solely for the
        // purpose of showing that it is a full-screen
        // undecorated JFrame.
        JLabel eastLabel = new JLabel("     East     ");
        eastLabel.setOpaque(true);
        eastLabel.setBackground(Color.RED);
        getContentPane().add(eastLabel,BorderLayout.EAST);
    
        JLabel southLabel =
                     new JLabel("South",SwingConstants.CENTER);
        southLabel.setOpaque(true);
        southLabel.setBackground(Color.GREEN);
        getContentPane().add(southLabel,BorderLayout.SOUTH);
    
        JLabel westLabel = new JLabel("     West     ");
        westLabel.setOpaque(true);
        westLabel.setBackground(Color.RED);
        getContentPane().add(westLabel,BorderLayout.WEST);
    
    //    JLabel centerLabel = new JLabel("Center",SwingConstants.CENTER);
    //    centerLabel.setOpaque(true);
    //    centerLabel.setBackground(Color.WHITE);
    //    getContentPane().add(centerLabel,BorderLayout.CENTER);
    
    	JTextArea textArea = new JTextArea(20, 30);
    	textArea.setText("I'm a JTextArea");
    	textArea.setLineWrap(true);
    	textArea.setEditable(false);
    	JScrollPane scrollPane = new JScrollPane(textArea);
        getContentPane().add(scrollPane,BorderLayout.CENTER);
    
        if (graphicsDevice.isFullScreenSupported()){
          // Enter full-screen mode witn an undecorated,
          // non-resizable JFrame object.
          setUndecorated(true);
          setResizable(false);
          //Make it happen!
          graphicsDevice.setFullScreenWindow(this);
          validate();
        }else{
          System.out.println("Full-screen mode not supported");
        }//end else
    
      }//end constructor
    
      //The following method is invoked when the used clicks
      // the exitButton
      public void actionPerformed(ActionEvent evt){
        //Restore the original display mode
        graphicsDevice.setDisplayMode(origDisplayMode);
        //Terminate the program
        System.exit(0);
      }//end actionPerformed
    }//end classListing 26

  6. #6
    Willi's Avatar
    Willi is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Default

    People said the world is small, and I think that internet made it smaller :D. This program is one of more than 600 tutorials of Richard G Baldwin and @camickr : I read so many tutorials in this series but I don't even touch them to find a solution for this problem. Such a shame! :(. Thank you!

    You can not enter text in the JTextArea because the setEditable() method has been disabled :

    Java Code:
    textArea.setEditable(false);
    @Fubarable : where can I find the Java's bug database? Thank you!

    Anyone who interested in the useful series of Richard G Baldwin can take a look at this : dickbaldwin.com (2 more posts to be able to post hyperlink :D)
    Write a program to achieve anything you want in your life!

  7. #7
    Willi's Avatar
    Willi is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Default

    In my program, I add some text inside the JTextArea and I got Full-Screen Exclusive Mode.
    Java Code:
    textArea.setText("haha");
    For the first thought, I thought this was the solution. But then for sure in camickr example, I cleared the line :
    Java Code:
    textArea.setText(""I am a JTextArea!);
    and the program still works!

    Uncomprehensible! The solution is still in the dark =))
    Write a program to achieve anything you want in your life!

  8. #8
    Willi's Avatar
    Willi is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Default

    OK OK!

    After studying the code above carefully, I found out the solution is to put all the components directly to the JFrame without putting it indirectly in a JPanel. =)))
    Last edited by Willi; 10-14-2009 at 08:33 PM.
    Write a program to achieve anything you want in your life!

Similar Threads

  1. Replies: 4
    Last Post: 10-13-2009, 02:10 PM
  2. Open a shell maximized (full screen)
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-25-2008, 02:27 PM
  3. Full screen test
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:24 PM
  4. how to set full screen dimensions
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:08 PM
  5. Full screen
    By Jack in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 05:49 AM

Posting Permissions

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