Re: Frame packing problem with JTextArea containing wrapped text
Lew wrote:
John B. Matthews wrote:
I am unable to reproduce this. Can you supply a short, compilable
example?
"<<<Klu>>>" wrote:
Well, the only other thing it could be
Almost certainly not the *only* other thing it *could* be.
is that I'm doing something like
frame.pack();
Dimension fs = frame.getSize();
Dimension ds = tools.minDimensions(MAX_FRAME_DIMENSIONS, fs)
frame.setSize(ds);
frame.setVisible(true);
but the size of the frame I'm seeing is well below
MAX_FRAME_DIMENSIONS, so this must be just doing the equivalent of
frame.setSize(frame.getSize())
which ought to be a no-op.
You should read the link John B. Matthews provided:
<http://pscode.org/sscce.html>
package zzzbugfind;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class Main {
public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JTextArea ta = new JTextArea("Lorem ipsum dolor" +
" sit amet, consectetur adipiscing elit." +
" Donec in neque at arcu vestibulum euismod" +
" non et nibh. Praesent est sem, consequat" +
" ut volutpat nec, tincidunt ut urna. Nam" +
" sed nulla ac dui interdum viverra eget eu" +
"nisi.");
ta.setEditable(false);
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setOpaque(false);
ta.setColumns(60);
JButton b = new JButton("foo");
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.LINE_AXIS));
p.add(Box.createHorizontalGlue());
p.add(b);
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new
BoxLayout(frame.getContentPane(),
BoxLayout.PAGE_AXIS));
frame.getContentPane().add(ta);
frame.getContentPane().add(p);
frame.pack();
frame.setVisible(true);
}
});
}
}
This is the result on my system:
http://i43.tinypic.com/2cyo1s7.jpg