Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

fitting JTextArea to JFrame size

Thread view: 
hayder.tarik@gmail.com - 25 May 2005 09:13 GMT
hi,
I'm writing a simple app, i want the JTextArea size to change when the
frame size changes, i used ComponentListener and the componentResized
for the frame, the problem is i don't know which methods will change
the size of the JTextArea i tried resize(e.getComponent().getSize());
but it didn't work!.
thanks in advance

regards,
Andrew Thompson - 25 May 2005 09:42 GMT
> ..i want the JTextArea size to change when the
> frame size changes

Use a layout manager, that is what they are for.

<sscce>
import java.awt.*;
import javax.swing.*;

class ResizableTextArea {
 public static void main(String[] args) {
   JFrame f = new JFrame( "Resizable TextArea" );
   f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
   Container c = f.getContentPane();
   c.setLayout( new BorderLayout() );
   c.add( new JScrollPane(
     new JTextArea("Text Area", 5,20) ),
     BorderLayout.CENTER );
   c.add( new JButton("UP"), BorderLayout.NORTH );
   c.add( new JTextField("DOWN"), BorderLayout.SOUTH );
   c.add( new JLabel("L"), BorderLayout.WEST );
   c.add( new JLabel("R"), BorderLayout.EAST );
   f.pack();
   f.setVisible(true);
 }
}
</sscce>

For GUI tutorials you might start here..
<http://java.sun.com/docs/books/tutorial/uiswing/index.html>

For GUI related questions, see here..
<http://www.physci.org/codes/javafaq.jsp#cljg>

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Thomas Weidenfeller - 25 May 2005 15:47 GMT
> I'm writing a simple app, i want the JTextArea size to change when the
> frame size changes, i used ComponentListener and the componentResized
> for the frame, the problem is i don't know which methods will change
> the size of the JTextArea i tried resize(e.getComponent().getSize());
> but it didn't work!.

Use layout managers instead.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.