jtextarea

JTextArea new line on shift + enter

旧时模样 提交于 2019-12-20 23:56:28
问题 I've added a keylistener to my JTextArea field, but it doesn't behave as I expected. inputTextArea.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent k) { //If the return button is hit, only set to a new line if shift is also down. if(k.getKeyChar() == KeyEvent.VK_ENTER) { if(k.isShiftDown()) { inputTextArea.append(" \n"); } else { //Send The Message... boolean cleanTextField = false; try { sendMessage(inputTextArea.getText()); cleanTextField = true; msgScrollPane

Java Textarea ScrollPane

一曲冷凌霜 提交于 2019-12-20 07:16:16
问题 I have created a textarea, and i need a scrollbar applied to the textarea when necessary (when the text gets too long down and it cant be read anymore). this is the code i have written, but for some reason, the scrollbar doesnt really come up? final JTextArea textArea = new JTextArea(); textArea.setEditable(false); textArea.setBounds(10, 152, 456, 255); textArea.setBorder(border); textArea.setLineWrap(true); sbrText = new JScrollPane(textArea); sbrText.setVerticalScrollBarPolicy(JScrollPane

JTextArea scroll to bottom only if text is appended

*爱你&永不变心* 提交于 2019-12-20 07:11:17
问题 I am trying to create a JTextArea which scrolls to bottom every time a text is appended to that text area. Otherwise, the user should be able to scroll top and see previous message. I used this code: JTextArea terminalText = new JTextArea(); JPanel terminal = new JPanel(); terminal.setLayout(new BorderLayout()); add(terminal); //Adds the terminal to mother JPanel //I added scrollbar to my JTextArea JScrollPane scroll = new JScrollPane(terminalText); terminal.add(scroll, BorderLayout.CENTER);

Password in JTextArea

爱⌒轻易说出口 提交于 2019-12-20 05:35:07
问题 Is there any way using JTextArea to hide the text when user types?? Kind of like password.. in JTextArea i have.. password: in last line and whatever user types in that line shouldn't be visible. I have tried with setForeground method to set font colour to textarea colour which makes text invisible but allows user to copy and paste. is there any workaround or how can i achieve this?? Please help 回答1: Here's what I was talking about in comments. Do note that this is just a quick example (might

JTextArea as console

こ雲淡風輕ζ 提交于 2019-12-20 04:45:30
问题 I have posted two pieces of code below. Both codes work fine individually. Now, when I run the file Easy, and click on the "Start" button, I want the class AddNumber to be implemented. I mean to say that, instead of the AddNumber running on the console, is there any way I could make AddNumber run in the JTextArea i have created in the first class upon clicking the "Start" button? I thought maybe by action listener?(the way we do in case of buttons) But I'm not sure. Is there any other way to

Mechanisms of setText() in JTextArea?

蹲街弑〆低调 提交于 2019-12-20 03:42:19
问题 I try to show some text in my JTextArea in runtime. But when I use a loop of setText to show text in order, it only show the text of the last loop Here is my code: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { for (int i=0;i<10;i++) jTextArea1.setText("Example "+i); } I want it to show "Example 1", "Example 2",..,"Example 9" . But it only show one time " Example 9 " Anyone can explain it for me?? 回答1: setText does just that, it "sets the text" of field to the value

Could be Text orientation of JTextArea changed by keyboard shortcut?

一笑奈何 提交于 2019-12-20 03:38:26
问题 A JTextArea has componenent orientation set to LEFT, so text is written from left to right. Sometimes, it happens that while the user is writing, the text orientation suddenly changes to right, so all the text appears aligned to right. I can't explain why this happens (I have no direct feedback by users), but I guess that, while the user is typing, he activates some keyboard shortcut which changes the text orientation. Does someone know how this can happen? Can be there something else which

Reading all new messages from my gmail using javamail

故事扮演 提交于 2019-12-20 03:24:12
问题 I have an application which contains a GUI, it is using Javamail. When i open this Jframe I have to see messages that are sent to my mail on a jTextArea . The problem is when i wrote my code it only shows just the last message sent. How do I display all new messages in my inbox? This is my code : private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { Properties props = new Properties(); props.put("mail.pop3.host", "pop.gmail.com"); props.put("mail.pop3.user", "mymail@gmail.com

JTextArea setText(veryLongString) is taking too much time

混江龙づ霸主 提交于 2019-12-20 03:19:36
问题 I have a very long string which I get from a book. I display it in a JTextArea by using the setText() method. It freezes the UI and takes a lot of time. How do I get around that? Here is as SSCCE: import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.SwingUtilities; @SuppressWarnings("serial") public class SSCCE extends JFrame { JTextArea textArea; public SSCCE() { String text = buildLongString(400000); textArea = new JTextArea(); textArea

How to stylize (make bold) text in a JTextArea?

扶醉桌前 提交于 2019-12-20 02:56:19
问题 JTextArea txt = new JTextArea(); StringBuffer sb = new StringBuffer(); sb.append("Employee Information"); sb.append("\n"); sb.append("Name:"); txt.setText(sb.toString()); Here I need to set "Employee Information" to BOLD format..How to do that.. I tried like this sb.append("<html><b>Employee Information</b></html>"); But its printing the text normally... how to make bold? 回答1: The JText Area is a plain text area, for styled text areas you need something like JEditorPane or JTextPane, take a