What is the best way to resize JTextArea vertical? I think I shoud put JTextArea into JScrollPane (and I can make a simple pane with scrollbar). But I want to JTextArea scroll by mouse vertical. I tried to use class according to this tut.:
<a href="https://tips4java.wordpress.com/2009/09/13/resizing-components/" rel="nofollow">https://tips4java.wordpress.com/2009/09/13/resizing-components/</a>, but it is able to resize component with all sides.
I want something like here:
<a href="http://www.w3schools.com/cssref/playit.asp?filename=playcss_resize&preval=vertical" rel="nofollow">http://www.w3schools.com/cssref/playit.asp?filename=playcss_resize&preval=vertical</a>
or something like textarea which you use to post answer to topic here.
<strong>EDIT:</strong>
My piece of code with class ComponentResizer (from <a href="https://tips4java.wordpress.com/2009/09/13/resizing-components/" rel="nofollow">https://tips4java.wordpress.com/2009/09/13/resizing-components/</a>)
<a href="https://tips4java.wordpress.com/2009/09/13/resizing-components/" rel="nofollow">https://tips4java.wordpress.com/2009/09/13/resizing-components/</a>, but it is able to resize component with all sides.
I want something like here:
<a href="http://www.w3schools.com/cssref/playit.asp?filename=playcss_resize&preval=vertical" rel="nofollow">http://www.w3schools.com/cssref/playit.asp?filename=playcss_resize&preval=vertical</a>
or something like textarea which you use to post answer to topic here.
<strong>EDIT:</strong>
My piece of code with class ComponentResizer (from <a href="https://tips4java.wordpress.com/2009/09/13/resizing-components/" rel="nofollow">https://tips4java.wordpress.com/2009/09/13/resizing-components/</a>)
Code:
package textsamplerdemo;
import javax.swing.*;
import java.awt.*;
public class TextSamplerDemo extends JPanel {
public TextSamplerDemo() {
setLayout(new BorderLayout());
JTextArea textArea = new JTextArea(10, 20);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
JScrollPane scrollPane = new JScrollPane(textArea);
ComponentResizer componentResizer = new ComponentResizer();
componentResizer.registerComponent(scrollPane);
add(scrollPane, BorderLayout.PAGE_START);
}
/**
* Create the GUI and show it. For thread safety, this method should be
* invoked from the event dispatch thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("TextSamplerDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add content to the window.
frame.add(new TextSamplerDemo());
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event dispatching thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//Turn off metal's use of bold fonts
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
}