向高手求助,路过要来看一下呀! 我在Frame里添加了一个panel,然后在panel里划线,如果划de线段超出屏幕的显示尺寸,如何作出滚动条呢,望高手赐教!希望给出源代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你个例子:import java.awt.*;import java.awt.event.*;import javax.swing.*; public class JTextAreaExample extends JFrame implements ActionListener{ public static void main(String[] argv) { JTextAreaExample mainApp = new JTextAreaExample(); } public JTextAreaExample() { super("JTextArea Example"); setBounds(0, 0, 300, 300); getContentPane().setLayout(null); setDefaultCloseOperation(EXIT_ON_CLOSE); // Create the textarea... textarea = new JTextArea(); textarea.setBounds(10, 10, 270, 200); // NEW -> // Create a scrollpane scrollPane = new JScrollPane(JScrollPane.VERTICAL_ SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setBounds(10, 10, 270, 200); scrollPane.add(textarea); scrollPane.setViewportView(textarea); // <- NEW // Create a button... button = new JButton("Copy Text Area to Console Window"); button.setBounds(10, 240, 270, 25); // Add the action listeners button.addActionListener(this); // Add the objects to the content pane... getContentPane().add(scrollPane); // MODIFIED getContentPane().add(button); setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getSource() == button) { System.out.println(textarea.getText()); } } JButton button; JTextArea textarea; JScrollPane scrollPane; // NEW} 要写个计算器。。。初步完成但问题很大很多 java大学教程课后习题答案 一道特殊的找零问题 问个CVS无法提交的问题 问个白痴问题 有谁知道上海晟峰软件怎么样 SWING和AWT学得特别烂 设置ClassLoader 正则式的中文问题!! 如何在AIX上装Tomcat啊! 一个超级郁闷的问题.(关于环境变量和Eclipse) 怎样提取两个excel文件中的内容,然后合并到新的excel表中
import java.awt.event.*;
import javax.swing.*;
public class JTextAreaExample extends JFrame implements
ActionListener
{
public static void main(String[] argv)
{
JTextAreaExample mainApp = new JTextAreaExample();
}
public JTextAreaExample()
{
super("JTextArea Example");
setBounds(0, 0, 300, 300);
getContentPane().setLayout(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// Create the textarea...
textarea = new JTextArea();
textarea.setBounds(10, 10, 270, 200);
// NEW ->
// Create a scrollpane
scrollPane = new JScrollPane(JScrollPane.VERTICAL_
SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBounds(10, 10, 270, 200);
scrollPane.add(textarea);
scrollPane.setViewportView(textarea);
// <- NEW
// Create a button...
button = new JButton("Copy Text Area to Console Window");
button.setBounds(10, 240, 270, 25);
// Add the action listeners
button.addActionListener(this);
// Add the objects to the content pane...
getContentPane().add(scrollPane); // MODIFIED
getContentPane().add(button);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button)
{
System.out.println(textarea.getText());
}
}
JButton button;
JTextArea textarea;
JScrollPane scrollPane; // NEW
}