473,473 Members | 4,185 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

JTextArea not displaying correct size

67 New Member
Ok my problem is that when it loads the JTextArea, it does not show the full component's width and height. I've tried specifying it with setrow, setcolumn, setprefferedsize, all of that. It does display if I start to highlight the text but not on the initial load.

Expand|Select|Wrap|Line Numbers
  1. import java.awt.Color;
  2. import java.awt.GridBagLayout;
  3. import javax.swing.ImageIcon;
  4. import javax.swing.JFrame;
  5. import javax.swing.JLabel;
  6. import javax.swing.JPanel;
  7. import javax.swing.JTextArea;
  8.  
  9. /**
  10.  * @author Hanshawc
  11.  */
  12.  
  13. public class MyDesk extends JFrame
  14. {
  15.    private JPanel panel;
  16.    private JTextArea questionBox;
  17.    private JPanel questionPanel;
  18.  
  19.    public static void main(String[] args)
  20.    {
  21.        MyDesk myDesk = new MyDesk();
  22.    }
  23.  
  24.    public MyDesk()
  25.    {
  26.        this.setTitle("MyDesk Alpha Version: 0.1");
  27.        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  28.        this.setSize(660,525);
  29.        this.setResizable(false);
  30.        this.setBackground(Color.WHITE);
  31.        this.add(getMainPanel());
  32.        this.add(getUI());
  33.        this.setVisible(true);
  34.    }
  35.  
  36.    private JPanel getUI()
  37.    {
  38.       JPanel userInterface = (JPanel) this.getGlassPane();
  39.       userInterface.setVisible(true);
  40.       userInterface.setLayout(new GridBagLayout());
  41.       userInterface.add(getQuestionPanel());
  42.       return userInterface;
  43.    }
  44.  
  45.    private JPanel getMainPanel()
  46.    {
  47.        panel = new JPanel();
  48.        panel.setSize(640,480);
  49.        panel.setBackground(Color.WHITE);
  50.        panel.add(getBackgroundImage());
  51.        return panel;
  52.    }
  53.  
  54.    private JLabel getBackgroundImage()
  55.    {
  56.        ImageIcon titleIcon = new
  57.        ImageIcon(getClass().getResource("background.jpg"));
  58.        JLabel titleLabel = new JLabel();
  59.        titleLabel.setIcon(titleIcon);
  60.        return titleLabel;
  61.    }
  62.  
  63.    private JPanel getQuestionPanel()
  64.    {
  65.        questionPanel = new JPanel();
  66.        questionPanel.add(getQuestionBox());
  67.        questionPanel.setBackground(Color.WHITE);
  68.  
  69.        return questionPanel;
  70.    }
  71.  
  72.    private JTextArea getQuestionBox()
  73.    {
  74.         questionBox = new JTextArea(getQuestion());
  75.         questionBox.setBackground(Color.WHITE);
  76.         questionBox.setLineWrap(true);
  77.         questionBox.setWrapStyleWord(true);
  78.         return questionBox;
  79.    }
  80.  
  81.    private String getQuestion()
  82.    {
  83.        String question = "Test question";
  84.        return question;
  85.    }
  86. }
Mar 10 '09 #1
1 3249
chanshaw
67 New Member
Duh, well sorta I had to add the ui before the mainpanel.
Mar 10 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: - ions | last post by:
Hello, i am relatively new to programming, Java being the first language im learning. At the moment im having trouble changing the setEnable value of a button, relative to the state of a JTextArea,...
1
by: Chris Williams | last post by:
I haven't done any Java programming for a good long bit, so this is probably something really silly but anyways, can anyone tell me why my JTextArea is not appearing when I run this? public...
11
by: Ian Davies | last post by:
Hello Im having problems displaying my images as thumbnails in a table. My code for producing the new width and height from the original image is as follows...
1
by: Colibasi | last post by:
I would like to have a JTextArea with a background white and text should be readonly. The way I tried is something like this: JTextArea text = new JTextArea(); text.setEditable(false);...
2
by: moumita | last post by:
I have the folowing code..the logic according to me is correct..but I dont know...the msg boxes are not displaying anything...am I supposed to change any settings ??? Public Class Form1
2
by: janaki112 | last post by:
Hi, Can u please help in getting the contents in the JTextArea and writing tat into a file and also writing the contents of the file in to JTextArea???? can u give me the class or function name...
3
by: olafatia | last post by:
import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import java.io.File; import java.util.*; /* <Applet Code="MyPaint.class" width=400 height=400>...
3
by: MiziaQ | last post by:
is there a way to position the jtextarea on the content pane in a certain location ?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.