日期:2014-05-18 浏览次数:20686 次
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.text.BadLocationException;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
public class Demo extends JPanel implements ActionListener {
private String newline = "\n";
protected JLabel actionLabel;
public Demo() {
setLayout(new BorderLayout());
//Create a label to put messages during an action event.
actionLabel = new JLabel("Type text in a field and press Enter.");
actionLabel.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
//Lay out the text controls and the labels.
JPanel textControlsPane = new JPanel();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
textControlsPane.setLayout(gridbag);
c.gridwidth = GridBagConstraints.REMAINDER; //last
c.anchor = GridBagConstraints.WEST;
c.weightx = 1.0;
textControlsPane.add(actionLabel, c);
textControlsPane.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Text Fields"),
BorderFactory.createEmptyBorder(5,5,5,5)));
//Create a text&