本文整理汇总了Java中javax.swing.JTextArea类的典型用法代码示例。如果您正苦于以下问题:Java JTextArea类的具体用法?Java JTextArea怎么用?Java JTextArea使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JTextArea类属于javax.swing包,在下文中一共展示了JTextArea类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MessageTextArea
import javax.swing.JTextArea; //导入依赖的package包/类
public MessageTextArea(boolean editable, String text, String labelText) {
setLayout(new BorderLayout());
area = new JTextArea("");
area.setSize(400, 400);
area.setWrapStyleWord(true);
area.setAutoscrolls(true);
area.setLineWrap(true);
area.setEditable(editable);
area.setText(text);
JScrollPane scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.getViewport().add(area);
scrollPane.setDoubleBuffered(true);
add(scrollPane, "Center");
JLabel message = new JLabel(labelText);
add(message, "North");
}
示例2: testSkipTestsAction
import javax.swing.JTextArea; //导入依赖的package包/类
@Test
public void testSkipTestsAction() throws Exception {
JTextArea area = new JTextArea();
area.setText("");
ActionMappings.SkipTestsAction act = new ActionMappings.SkipTestsAction(area);
act.actionPerformed(new ActionEvent(area, ActionEvent.ACTION_PERFORMED, "X"));
assertTrue(area.getText().contains(TestChecker.PROP_SKIP_TEST + "=true"));
area.setText(TestChecker.PROP_SKIP_TEST + "=false");
act.actionPerformed(new ActionEvent(area, ActionEvent.ACTION_PERFORMED, "X"));
assertTrue(area.getText().contains(TestChecker.PROP_SKIP_TEST + "=true"));
area.setText(TestChecker.PROP_SKIP_TEST + " = false\nyyy=xxx");
act.actionPerformed(new ActionEvent(area, ActionEvent.ACTION_PERFORMED, "X"));
assertTrue(area.getText().contains(TestChecker.PROP_SKIP_TEST + "=true"));
area.setText("aaa=bbb\n" + TestChecker.PROP_SKIP_TEST + " = false \nyyy=xxx");
act.actionPerformed(new ActionEvent(area, ActionEvent.ACTION_PERFORMED, "X"));
assertTrue(area.getText().contains(TestChecker.PROP_SKIP_TEST + "=true"));
}
示例3: btnStackActionPerformed
import javax.swing.JTextArea; //导入依赖的package包/类
private void btnStackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStackActionPerformed
StringWriter sw = new StringWriter();
exception.printStackTrace(new PrintWriter(sw));
JPanel pnl = new JPanel();
pnl.setLayout(new BorderLayout());
pnl.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
JTextArea ta = new JTextArea();
ta.setText(sw.toString());
ta.setEditable(false);
JScrollPane pane = new JScrollPane(ta);
pnl.add(pane);
pnl.setMaximumSize(new Dimension(600, 300));
pnl.setPreferredSize(new Dimension(600, 300));
NotifyDescriptor.Message nd = new NotifyDescriptor.Message(pnl);
DialogDisplayer.getDefault().notify(nd);
}
示例4: doTest
import javax.swing.JTextArea; //导入依赖的package包/类
private static void doTest(Runnable action) {
String description
= " A print dialog will be shown.\n "
+ " Please select Pages within Page-range.\n"
+ " and enter From 2 and To 3. Then Select OK.";
final JDialog dialog = new JDialog();
dialog.setTitle("JobAttribute Updation Test");
JTextArea textArea = new JTextArea(description);
textArea.setEditable(false);
final JButton testButton = new JButton("Start Test");
testButton.addActionListener((e) -> {
testButton.setEnabled(false);
action.run();
});
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(textArea, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(testButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
dialog.add(mainPanel);
dialog.pack();
dialog.setVisible(true);
}
示例5: createAndShow
import javax.swing.JTextArea; //导入依赖的package包/类
public void createAndShow() throws Exception{
Preferences Config = TEdit.getConfig();
JTextArea area = new JTextArea(10,40);
area.setEditable(false);
String Font_Name = Config.get("FONT_NAME","Monospaced");
int Font_Size = Config.getInt("FONT_SIZE",12);
int Font_Style = Config.getInt("FONT_STYLE",Font.PLAIN);
area.setFont(new Font(Font_Name,Font_Style,Font_Size));
JScrollPane scroll = new JScrollPane(area,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
this.add(scroll,BorderLayout.CENTER);
if(txt == null){
BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("org/ioblako/edit/resources/Help.txt"), "UTF-8"));
for (int c = br.read(); c != -1; c = br.read()) sb.append((char)c);
txt=sb.toString();
}
area.setText(txt);
this.setTitle("Help");
this.pack();
this.setVisible(true);
}
示例6: LogReaderPanel
import javax.swing.JTextArea; //导入依赖的package包/类
/**
* Konstruktor.
*
* Zeigt einen schreibgeschützten Editor an.
*
* @param logFileName der Name der Log Datei
*/
public LogReaderPanel(String logFileName)
{
super(new BorderLayout());
String logPath = PathHelper.getBasePath();
logFile = new File(logPath + logFileName);
textArea = new JTextArea("Keine Logs geladen!");
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
add(scrollPane, BorderLayout.CENTER);
reloadButton = new JButton("Laden");
reloadButton.addActionListener(this);
add(reloadButton, BorderLayout.SOUTH);
}
示例7: actionPerformed
import javax.swing.JTextArea; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
JTextArea area = TEdit.getTextArea();
String txt = area.getText();
if(txt == null)
return;
String s = TEdit.getLookingFor();
if(s.contentEquals(""))
return;
if(txt.contentEquals("") || txt.length()<1)
return;
if(area.getCaretPosition() >=txt.length()-1){
area.setCaretPosition(0);
//JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the end of the text");
//return;
}
int foundAt = txt.indexOf(s,area.getCaretPosition()+s.length());
if(foundAt == -1){
JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the end of the text");
return;
}
area.setCaretPosition(foundAt);
area.select(foundAt,foundAt+s.length());
}
示例8: testReplaceAll10
import javax.swing.JTextArea; //导入依赖的package包/类
/**
* Test of replaceAll method, of class EditorFindSupport.
*/
@Test
public void testReplaceAll10() throws Exception {
final Map<String, Object> props = new HashMap<>();
props.put(EditorFindSupport.FIND_WHAT, "a");
props.put(EditorFindSupport.FIND_REPLACE_WITH, "b");
props.put(EditorFindSupport.FIND_HIGHLIGHT_SEARCH, Boolean.TRUE);
props.put(EditorFindSupport.FIND_INC_SEARCH, Boolean.TRUE);
props.put(EditorFindSupport.FIND_BACKWARD_SEARCH, Boolean.FALSE);
props.put(EditorFindSupport.FIND_WRAP_SEARCH, Boolean.FALSE);
props.put(EditorFindSupport.FIND_MATCH_CASE, Boolean.FALSE);
props.put(EditorFindSupport.FIND_SMART_CASE, Boolean.FALSE);
props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.FALSE);
props.put(EditorFindSupport.FIND_REG_EXP, Boolean.FALSE);
props.put(EditorFindSupport.FIND_HISTORY, new Integer(30));
final EditorFindSupport instance = EditorFindSupport.getInstance();
JTextArea ta = new JTextArea("aa");
ta.setCaretPosition(1);
instance.replaceAllImpl(props, ta);
assertEquals("ab", ta.getText());
}
示例9: runTest
import javax.swing.JTextArea; //导入依赖的package包/类
private static void runTest() {
JDialog dialog = Util
.createModalDialogWithPassFailButtons("Empty header showing \"...\"");
String[] columnNames = {"", "", "", "", "Testing"};
String[][] data = {{"1", "2", "3", "4", "5"}};
JTable table = new JTable(data, columnNames);
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
int tableCellWidth = renderer.getFontMetrics(renderer.getFont())
.stringWidth("test");
table.setPreferredScrollableViewportSize(new Dimension(
5 * tableCellWidth, 50));
JPanel p = new JPanel();
p.add(new JScrollPane(table));
dialog.add(p, BorderLayout.NORTH);
JTextArea area = new JTextArea();
String txt = "\nInstructions:\n\n";
txt += "Only the last column header should show \"...\".";
area.setText(txt);
dialog.add(new JScrollPane(area), BorderLayout.CENTER);
dialog.pack();
dialog.setVisible(true);
}
示例10: initAndShowUI
import javax.swing.JTextArea; //导入依赖的package包/类
private static void initAndShowUI() {
frame = new JFrame("Test frame");
frame.setSize(SIZE, SIZE);
frame.setLocationRelativeTo(null);
final JTextArea jta = new JTextArea();
jta.setBackground(Color.RED);
frame.add(jta);
jta.setText("1234567890");
jta.setFont(jta.getFont().deriveFont(150f));
jta.setDragEnabled(true);
jta.selectAll();
jta.setDropTarget(new DropTarget(jta, DnDConstants.ACTION_COPY,
new TestdropTargetListener()));
jta.addMouseListener(new TestMouseAdapter());
frame.setVisible(true);
}
示例11: DevelopmentJMenuItem
import javax.swing.JTextArea; //导入依赖的package包/类
/**
* Constructs
*
* @param objPcontrolJFrame
*/
public DevelopmentJMenuItem(ControlJFrame objPcontrolJFrame) {
this.objGcontrolJFrame = objPcontrolJFrame;
this.objGdevelopmentJTextArea = new JTextArea(25, 80);
this.objGdevelopmentJTextArea.setFont(new Font("Courier", Font.PLAIN, 11));
this.objGdevelopmentJTextArea.setOpaque(true);
this.objGdevelopmentJTextArea.setEditable(false);
this.objGcloseExtendedJButton = new ExtendedJButton(objPcontrolJFrame, this);
// Build dialog :
this.objGdevelopmentJDialog = this.getDevelopmentDialog(objPcontrolJFrame, this.objGdevelopmentJTextArea, this.objGcloseExtendedJButton);
this.setOpaque(true);
this.addActionListener(this);
this.setAccelerator(Constants.keyS_DEVELOPMENT);
}
示例12: initialize
import javax.swing.JTextArea; //导入依赖的package包/类
private void initialize() {
txtArea = new JTextArea();
txtArea.setFont(new Font(Font.SANS_SERIF, 0, 12));
txtArea.setEditable(false);
JScrollPane sp = new JScrollPane(txtArea);
sp.setBounds(5, 5, 600, 410);
frame.getContentPane().add(sp);
btnOk = new JButton("OK");
btnOk.setFont(new Font(Font.SANS_SERIF, 0, 12));
btnOk.setBounds(510, 420, 95, 20);
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
});
frame.getContentPane().add(btnOk);
txtArea.append(new Utils().getLicenseFile());
txtArea.setCaretPosition(0);
}
示例13: LogWindowPanel
import javax.swing.JTextArea; //导入依赖的package包/类
/**
* Constructor
*/
private LogWindowPanel() {
this.setSize(500, 400);
this.setVisible(false);
jLogTextArea = new JTextArea();
TextAreaAppender.setTextArea(jLogTextArea);
JPanel thePanel = new JPanel(new BorderLayout());
JScrollPane scrollPane = new JScrollPane(jLogTextArea);
thePanel.add(scrollPane);
this.add(thePanel);
/*
* On close update notification tray
*/
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
if(displayLogItem != null) {
displayLogItem.setLabel("Afficher les traces");
displayLogItem.setState(false);
}
}
});
}
示例14: ToolBarDemo2
import javax.swing.JTextArea; //导入依赖的package包/类
public ToolBarDemo2() {
super(new BorderLayout());
// Create the toolbar.
JToolBar toolBar = new JToolBar("Still draggable");
addButtons(toolBar);
toolBar.setFloatable(false);
toolBar.setRollover(true);
// Create the text area used for output. Request
// enough space for 5 rows and 30 columns.
textArea = new JTextArea(5, 30);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
// Lay out the main panel.
setPreferredSize(new Dimension(450, 130));
add(toolBar, BorderLayout.PAGE_START);
add(scrollPane, BorderLayout.CENTER);
}
示例15: onClick
import javax.swing.JTextArea; //导入依赖的package包/类
@Override
public void onClick(ActionEvent i_Event)
{
String v_CMD = ((JTextArea)XJava.getObject("xtPutsInfo")).getText();
if ( JavaHelp.isNull(v_CMD) )
{
this.getAppFrame().showHintInfo("请输入要执行的命令" ,Color.BLUE);
return;
}
try
{
AppMain.executes(v_CMD);
super.onClick(i_Event);
this.getAppFrame().showHintInfo("执行完成,请查看控制台日志" ,Color.BLUE);
}
catch (Exception exce)
{
this.getAppFrame().showHintInfo("执行命令异常:" + exce.getMessage() ,Color.RED);
}
}