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

Resizable border between text areas  RSS feed

 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a typical Instant Messaging chat window, there are 2 text areas - 1 on top and another on the bottom.

Usually we can freely shift the border between the 2 text areas - up and down, thus resizing the text areas. 1 will grow larger as the other grows smaller.

How can I implement this with AWT ? Some sample code would be appreciated.

Thanks a lot.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSplitPane
 
Stephen Boston
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IN your GUI constructor...



panel1 and panel2 hold different components and other panels for my project. I split the frame and added the two panel with the above code.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed you specified AWT, is Swing unacceptable for some reason?

If you can use Swing, then JSplitPane is the class you want and has already been mentioned. As this is an instant messaging program you most likely want a VERTICAL_SPLIT with one component on top of the other rather than a horizontal as was defined in the above post. You should also be aware of the resizeWeight property which has a value of 0.0 (defualt) to 1.0. 0.0 will assign all extra space to the right/bottom component, and if your program follows the typical form that's probably reverse of what you want. 1.0 would assign it to the top/left component (which is likely your receiving window). Also, the divider location can be set using a double to make it proportional rather than an absolute which was used in the above post.

If it must be AWT only it will be much more annoying to do.
 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn, thanks for telling me it's a JSplitPane that I should use.

Stephen Boston, thanks for the sample code.

Ken Blair, thanks for being meticulous - realized that my question was asking for a AWT solution. This is because my current code (done half way) is in AWT. Looks like I'll have to just switch to Swing... rewriting my code. Thanks for customizing your answers to my needs (VERTICAL_SPLIT etc). Thanks for informing that "If it must be AWT only it will be much more annoying to do".

I searched the net for JSplitPane ... and landed myself on this very informative page :
http://java.sun.com/docs/books/tutorial/uiswing/components/splitpane.html

Thanks all for your time. Appreciate it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!