Re: Wrap text dont ajust
To: comp.lang.java.gui
Paulo Filipe wrote:
Also, The line lengths were very long (just because
the HTML was long, did not mean the code lines
had to be!) and they wrapped and needed to be
fixed before the code would compile.
Please try to keep the lines under 63 chars.
Your second code example was broken due
to wrapped lines as well!
i found this topic:
http://groups.google.com/group/comp.lang.java.gui/browse_thread/thread/db311ad88332fbb9/f27e21f638efd5dc?lnk=gst&q=Preferred+Size&rnum=2#f27e21f638efd5dc
where they discuss a similar problem, but i dont understand this:
"A general approach is to have the getPreferredSize() method of a
component set the width of the component to the width that you want,
invoke validate on the component, determine the maximum height value
used by the component when it laidout itself in the validate method.
How the last step is done depends on the component. "
Uh-huh..
I'm calling validate now, although i dont know yet to work with this
well. I try pack but didn't respect the size i set to the frame.
You can set the frame size afterwards.
Please read the JavaDocs on all these methods, and
ask questions about anything that you do not understand.
It seems as if you are programming by 'typing random
statements', in the hope they will fix the problem.
I rewrite the code:
(that was much closer to the SSCCE I was hoping for)
Try my version, though I am still not entirely sure what
effect we are wanting..
<sscce>
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.*;
public class SimpleGuiTest2 {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(){
public Dimension getPreferredSize() {
Dimension temp = super.getPreferredSize();
return new Dimension( 20, temp.height );
}
};
panel.setLayout(new
BoxLayout(panel, BoxLayout.Y_AXIS));
JLabel long_label = new JLabel(
"<html>A very, very, very long label.</html>");
JLabel tall_label = new JLabel(
"<html>Begin br's <br><br>Middle<br><br>End</html>");
panel.add(long_label);
panel.add(tall_label);
JScrollPane scrollPag = new JScrollPane(panel);
scrollPag.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// create and configure the layout
Container conteudo = frame.getContentPane();
conteudo.setLayout(new BorderLayout());
// insert the scrollpane
conteudo.add(scrollPag,BorderLayout.CENTER);
// or panel..
// conteudo.add(panel,BorderLayout.CENTER);
frame.pack();
// comment if no scrollpane
frame.setSize(100, 100);
frame.setVisible(true);
}
}
</sscce>
Andrew T.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24