• Post Reply Bookmark Topic Watch Topic
  • New Topic

JScrollPane won't resize to JPanel height as intended

 
J.D. Thompson
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys!

At the bottom of my GUI, I have have a JTextArea inside of a JScrollPane inside of a JPanel inside of a JSplitPane.

The desired effect is as messages are received from the field, that they be added to the JTextArea (thus it grows with time) for display. Once it reaches the JPanel limits, scroll bars should appear thus allowing the user to resize the bottom according depending upon how many messages they have received.

m_statusScroll is the JScrollPane, m_statusArea is the JTextArea, and the parent of m_statusScroll is the JPanel. Below is the most recent code on my attempt to resize:

m_statusScroll.addComponentListener(new ComponentAdapter()
{
public void componentResized(ComponentEvent e)
{
int m_panelHeight=m_statusScroll.getParent().getHeight();
int m_scrollHeight=m_statusScroll.getHeight();
int m_scrollWidth=m_statusScroll.getWidth();
int m_statusAreaHeight=m_statusArea.getHeight();

m_statusScroll.getViewport().setExtentSize(new Dimension(
m_panelHeight-15,m_scrollWidth));
}
});

Let's say that the JPanelHeigh is 156 (via the SplitPane), as messages are added AND the JTextArea height remains less than 156, then the above code works as intended, however, once 156 is reached the JScrollPane collapses to a one line height.

I have tried setting the preffered size of the JScrollPane and only get the same results.

I used a gridbaglayout to setup the JFrame and the JSplitPane.

Please let me know what you think might work or what concept I am missing. Thanks to all who take the time to reply to this posting!!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> At the bottom of my GUI, I have have a JTextArea inside of a JScrollPane
> inside of a JPanel inside of a JSplitPane.

I can't see the need for the JPanel.

If your code was just this
new JSplitPane(JSplitPane.VERTICAL_SPLIT,new JPanel(),new JScrollPane(new JTextArea(5,10)));
it should work the way you want, without using a componentListener
 
J.D. Thompson
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael for replying!!

I have to have the JPanel because it actually houses two components, the JScrollPane and a second JPanel(which has the system time and date displayed).

Sorry that I left that detail off.

JD
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the JPanel was set to a BorderLayout, with scrollpane at CENTER, and the
time/date panel at SOUTH(assuming it is under the scrollpane), it should still
work OK
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!