?
Solved

set the size of a JTextFrame

Posted on 2005-03-17
13
Medium Priority
?
600 Views
Last Modified: 2012-06-21
Experts

I have created a JTextFrame but can not seem to set the initial size of it even though i have included this in the ststement:

public JTextArea ServerData = new JTextArea(20,40);

It just produces the very top of the window, i have to drag it to size it.

Any ideas?

Regards

K
0
Comment
Question by:kephillips
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 13564547
Use
ServerData.setPreferredSize()
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13564554
The initial size is determined by the layout manager. You can try setPreferredSize(new Dimension(20, 40)) but it could be ignored
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13564559
>> I have created a JTextFrame
>> public JTextArea
Are you talking about a JFrame or a JTextArea?
0
Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

 
LVL 37

Expert Comment

by:zzynx
ID: 13564570
Is the whole JFrame badly sized or just the JTextArea in the JFrame?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13564593
Please post your code
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13564610
>>setPreferredSize(new Dimension(20, 40))

or whatever dimension ;-)

If you're using a null layout and have not set the size for each component explicitly, the frame effectively will have a zero client component dimension, which means you'll only see the title bar
0
 

Author Comment

by:kephillips
ID: 13564622
i have publicly declared:

 public JTextArea ServerData = new JTextArea(20,40);


Then in the constructor created:

JFrame serverFrame = new JFrame("Server Data");
   
    JScrollPane ppServerLog = new JScrollPane(ServerData);
    add (ppServerLog,"Center");
    ServerData.setEditable(false);
    serverFrame.getContentPane().add(ppServerLog);
   
    serverFrame.show();

Regards

0
 
LVL 35

Expert Comment

by:TimYates
ID: 13564636
Tried resizing the scrollpane?

That't the thing you want to be setting the size of (as it contains your textArea)
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 13564644
Try this:

    JFrame serverFrame = new JFrame("Server Data");
   
    JScrollPane ppServerLog = new JScrollPane(ServerData);
    ServerData.setEditable(false);
    serverFrame.getContentPane().add(ppServerLog, BorderLayout.CENTER);
    serverFrame.setSize(500,500);
   
    serverFrame.show();
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13564647
   JScrollPane ppServerLog = new JScrollPane(ServerData);
    ppServerLog.setPreferredSize( ServerData.getPreferredSize() ) ;
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13564656
JScrollPane ppServerLog = new JScrollPane(ServerData);
serverFrame.getContentPane().add(ppServerLog, BorderLayout.CENTER);
serverFrame.show();
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13564765
So you were talking about the JFrame
Thanks for accepting
0
 

Author Comment

by:kephillips
ID: 13564968
Yes thanks for all your help guys/girls
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question