Results 1 to 2 of 2
  1. #1
    paul is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default Help with JTextArea, resize windows

    How can I get the JTextArea to display without having to resize the window?
    And is there a way I can position it?
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.util.Random;
    
    public class Oval extends JPanel {
        
        public void paintComponent( Graphics g ) {
            super.paintComponent( g );
            
            Random randomNumbers = new Random();
            int width = 1 + randomNumbers.nextInt( 200 );
            int height = 1 + randomNumbers.nextInt( 200 );
            
            double area = Math.PI * (width/2) * (height/2);
            
            String text = "Area = " + area + "\n";
            JTextArea textArea1 = new JTextArea( text, 10, 10 );
            
            add (textArea1);
          
            //( int x, int y, int width, int height )
            g.drawOval( 10, 10, width, height );
        }
    }
    Java Code:
    import javax.swing.JFrame;
    
    public class OvalTest {
            
        public static void main(String args[]) {
            JFrame frame = new JFrame( "Oval of random size" );
            frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            frame.setSize( 600, 210 );
            
            Oval oval = new Oval();
            
            frame.add(oval);
            
            frame.setVisible( true );
        }
    }
    Thanks

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    You need to learn layout managers to be able to place the component to the position you want.

Similar Threads

  1. Moments with Windows
    By tim in forum Entertainment
    Replies: 13
    Last Post: 11-10-2009, 01:34 PM
  2. Replies: 1
    Last Post: 02-17-2008, 12:43 AM
  3. swt for windows
    By Gajesh Tripathi in forum SWT / JFace
    Replies: 2
    Last Post: 10-18-2007, 07:43 AM
  4. resize tabs in jtabbedpane
    By osval in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 04:02 AM
  5. Resize frame
    By lenny in forum AWT / Swing
    Replies: 1
    Last Post: 07-30-2007, 12:18 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
  •