如何在JScrollPane中放置JTextArea,设置字体和边距,以及设置滚动条
Xn_warm
・1 分钟阅读
我使用以下Scala源代码创建Java JTextArea组件,设置它字体,使它只读,设置它边距(插入),然后将textarea放入JScrollPane:
// text area val textArea = new JTextArea(textAreaRows, textAreaColumns) textArea.setFont(new Font(\"Helvetica Neue\", Font.PLAIN, 20)) textArea.setEditable(false) textArea.setMargin(new Insets(12, 12, 12, 12)) textArea.setText(textToDisplay) // scrollpane val scrollPane = new JScrollPane(textArea) scrollPane.setPreferredSize(windowSize) scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS)
虽然代码是用Scala编写的,但是可以很容易地转换为Java,如果希望在JScrollPane
中设置JTextArea
的组合,设置,字体或边距,设置滚动窗格大小和/或控制。