private JPanel Panel () {
JPanel panel = new JPanel();
Font font = new Font("Arial", Font.BOLD, 18);
panel.setLayout(new BorderLayout());
inText = new JTextArea();
inText.setEditable(false);
inText.setFont(font);
inText.setLineWrap(true);
inText.setWrapStyleWord(true);
JScrollPane inTextScroller = new JScrollPane(inText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
panel.add(inTextScroller, BorderLayout.CENTER);
outText = new JTextArea(2, 1);
outText.addKeyListener(listen);
outText.setFont(font);
outText.setLineWrap(true);
outText.setWrapStyleWord(true);
JScrollPane outTextScroller = new JScrollPane(outText, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
panel.add(outTextScroller, BorderLayout.SOUTH);
return panel;
}
JTextArea question
Started by seanbp, Jul 17 2010 10:00 PM
8 replies to this topic
#1
Posted 17 July 2010 - 10:00 PM
Why do I need JScrollPane to get JTextArea's layout to behave properly?
|
|
|
#2
Posted 19 July 2010 - 02:36 AM
What's wrong with the layout without scrollpanes?
#3
Posted 19 July 2010 - 09:55 AM
The dimensions are all wrong; it gets way too large. I need to resize my frame just to see the other text area.
#4
Posted 19 July 2010 - 10:47 PM
#5
Posted 19 July 2010 - 11:04 PM
THIS is is buggy code... THAT was using a scroller. sorry for the confusion.
private JPanel panel () {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
Font font = new Font("Arial", Font.BOLD, 12);
Listen listen = new Listen();
inText = new JTextArea();
inText.setEditable(false);
inText.setFont(font);
inText.setLineWrap(true);
inText.setWrapStyleWord(true);
JScrollPane inTextScroller = new JScrollPane(inText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
panel.add(inTextScroller, BorderLayout.CENTER);
outText = new JTextArea(2, 1);
outText.addKeyListener(listen);
outText.setFont(font);
outText.setLineWrap(true);
outText.setWrapStyleWord(true);
//JScrollPane outTextScroller = new JScrollPane(outText, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
panel.add(outText, BorderLayout.SOUTH);
return panel;
}
#6
Posted 19 July 2010 - 11:25 PM
That looks like
Test2.JPG 11.85K
173 downloads...
Tested with:
Test2.JPG 11.85K
173 downloads...Tested with:
public static void main(String[] args) {
JFrame frame = new JFrame("test");
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
Font font = new Font("Arial", Font.BOLD, 12);
JTextArea inText = new JTextArea();
inText.setEditable(false);
inText.setFont(font);
inText.setLineWrap(true);
inText.setWrapStyleWord(true);
inText.setText("test text");
inText.setBackground(Color.cyan);
JScrollPane inTextScroller = new JScrollPane(inText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
panel.add(inTextScroller, BorderLayout.CENTER);
JTextArea outText = new JTextArea(2, 1);
outText.setFont(font);
outText.setLineWrap(true);
outText.setWrapStyleWord(true);
//JScrollPane outTextScroller = new JScrollPane(outText, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
panel.add(outText, BorderLayout.SOUTH);
frame.add(panel);
frame.setSize(800,600);
frame.setVisible(true);
}
#7
Posted 19 July 2010 - 11:46 PM
must be unique to my os or probably the environment. thanks for the help.
#8
Posted 19 July 2010 - 11:53 PM
Java should be OS-independant so OS shouldn't really matter. Perhaps your screen DPI can mess up layout if it's set to something different than 96DPI..
#9
Posted 20 July 2010 - 10:01 AM
DPI is 96.
You're right, it should be independent. I'm using OpenJDK. I've attached some screenshots...
The second text area resizes to it's content and overlaps the other text area. Perhaps the two are incompatible with each-other with respect to the layout.
You're right, it should be independent. I'm using OpenJDK. I've attached some screenshots...
The second text area resizes to it's content and overlaps the other text area. Perhaps the two are incompatible with each-other with respect to the layout.


Sign In
Create Account

Back to top









