Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JScrollPane collapses after minimizing GUI  RSS feed

James Ajewole
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTextArea component which i want to use to capture some text and
a JScrollPane for the scrollable view. what happens is that when the program
runs initially, everything is arranged as i expect it to be (using the GridBag Layout), but after i type text in the TextArea and lets say i happen to minimize the GUI and maximize it again, the ScrollPane collapses vertically to almost half the original size and distorts the GUI. The code that creates the TextArea and the scrollpane is as follows.

txtMessage.setFont(new Font("Arial", 0, 12));
txtMessage.setBorder(new javax.swing.border.BevelBorder (javax.swing.border.BevelBorder.LOWERED));
txtMessage.getDocument().addDocumentListener(new MyDocumentListener());
JScrollPane displayScrollPane = new JScrollPane(txtMessage);
c.gridx = 1;
c.gridy = 1;
c.weightx = 1.0;
c.weighty = 1.0;
c.gridwidth = 6;
c.ipadx = 0;
c.ipady = 40;
c.insets = new Insets(3, 3, 3, 3);
single.add(displayScrollPane, c);

any ideas on how to stop the scrollpane from collapsing.

Warren Dew
Ranch Hand
Posts: 1332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to remember there's a JTextArea method, possibly inherited, that says to get the sizing from the container. I could be misremembering.

There could also be some other component in the grid bag that is affecting the sizing of the grid bag's columns and rows.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!