JTextAreaを垂直方向にリサイズする最適な方法は何ですか?私はJTextAreaをJScrollPaneに入れて(そして私はスクロールバーを使って簡単なペインを作ることができる)と思っています。しかし、私は、JTextAreaをマウスの垂直方向にスクロールする必要があります。このチュートに従ってクラスを使いこなそうとしました。 https://tips4java.wordpress.com/2009/09/13/resizing-components/ですが、すべての面でコンポーネントのサイズを変更することができます。JTextAreaを垂直方向にリサイズする
私はここで何かしたい:あなたはここで話題に答えを投稿するときに使用
http://www.w3schools.com/cssref/playit.asp?filename=playcss_resize&preval=vertical
またはテキストエリアのようなものを。
EDIT:(https://tips4java.wordpress.com/2009/09/13/resizing-components/から)クラスComponentResizerとコードの
マイピース
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();
}
});
}
}
適切なレイアウトとレイアウトの制約を使用してください。 'BorderLayout'の' LINE_START'か 'LINE_END'はそれを行います。レイアウトにサイズを示すために、テキスト領域に定義された数の列と行を指定してください。 –
あなたはこれのような意味ですか? 'setLayout(new BorderLayout()); JTextArea textArea =新しいJTextArea(10,20); ComponentResizer componentResizer = new ComponentResizer(); componentResizer.registerComponent(textArea); add(textArea、BorderLayout.PAGE_START); ' – Jan444444
@AndrewThompsonは 'LINE_START'または' LINE_END'を指定しました。なぜそれを見てみてください。コメントのコードを読みにくいので、あなたの修正されたアプローチを示す[mcve]を含むように質問を編集してください。名前で参加者を呼び出すには '@'を使います。 – trashgod