David0099
David0099

Reputation: 1

JTextPane is going out of boundary from JDialog

chatTextPane = new JTextPane();
chatTextPane.setPreferredSize(new Dimension(350,150));
//chatTextPane.setMaximumSize(new Dimension(350,150));//new
scrollingTextPane = new JScrollPane(chatTextPane);
scrollingTextPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollingTextPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//scrollingTextPane.setMaximumSize(new Dimension(350,150));

I'm writing a chat program on JDialog. My JTextPane is going out of boundary from the JDialog. I have added two pictures. One is before closing the JDialog window and the other is after opening the JDialog window again.

Upvotes: 0

Views: 73

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347334

Get rid of chatTextPane.setPreferredSize(new Dimension(350,150));. It's prevent it from telling the JScrollPane how big it should be.

Take a look at Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing? for more reasons why you should avoid using setPreferredSize...just in case your mistake this time didn't make it clear ;)

Upvotes: 3

Related Questions