?
Solved

set the size of a JTextFrame

Posted on 2005-03-17
13
Medium Priority
?
614 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

621 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