當前位置: 首頁>>代碼示例>>Java>>正文


Java JTextArea類代碼示例

本文整理匯總了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");
}
 
開發者ID:addertheblack,項目名稱:myster,代碼行數:21,代碼來源:MessageWindow.java

示例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"));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:ActionMappingsTest.java

示例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);

}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:ErrorPanel.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:JobAttrUpdateTest.java

示例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);
               
}
 
開發者ID:mathhobbit,項目名稱:EditCalculateAndChart,代碼行數:23,代碼來源:HelpFrame.java

示例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);
}
 
開發者ID:Entwicklerpages,項目名稱:school-game,代碼行數:26,代碼來源:LogReaderPanel.java

示例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());
}
 
開發者ID:mathhobbit,項目名稱:EditCalculateAndChart,代碼行數:25,代碼來源:FindRight_Action.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:EditorFindSupportTest.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:bug6442918a.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:MissingDragExitEventTest.java

示例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);
}
 
開發者ID:jugglemaster,項目名稱:JuggleMasterPro,代碼行數:21,代碼來源:DevelopmentJMenuItem.java

示例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);
}
 
開發者ID:JudgeGlass,項目名稱:Install_Builder_Universal,代碼行數:22,代碼來源:GNULicenseWindow.java

示例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);
			}
	    }
	});
}
 
開發者ID:OwaNotifier,項目名稱:owa-notifier,代碼行數:29,代碼來源:LogWindowPanel.java

示例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);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:21,代碼來源:ToolBarDemo2.java

示例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);
    }
}
 
開發者ID:HY-ZhengWei,項目名稱:HBaseClient,代碼行數:25,代碼來源:ExecutePutAction.java


注:本文中的javax.swing.JTextArea類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。