jtextarea

Java JTextArea that auto-resizes and scrolls

倾然丶 夕夏残阳落幕 提交于 2019-12-23 07:01:24
问题 I have a JTextArea in a JPanel. How can I have the JTextArea fill the whole JPanel and resize when the JPanel resizes and scroll when too much text is typed in? 回答1: JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); //give your JPanel a BorderLayout JTextArea text = new JTextArea(); JScrollPane scroll = new JScrollPane(text); //place the JTextArea in a scroll pane panel.add(scroll, BorderLayout.CENTER); //add the JScrollPane to the panel // CENTER will use up all available

Java - Changing background color of a nonstatic JTextArea that needs to appear in multiple windows simultaneously

ε祈祈猫儿з 提交于 2019-12-23 05:16:08
问题 If I have a static JTextArea object, I am able to change its color using name.setBackground(Color c); . However, if the JTextArea object is not static, I can't use methods like name.setText(String s) or name.setBackground(Color c); . I need the objects to be nonstatic because I need to run multiple instances of them simultaneously in multiple windows. 回答1: You cannot display multiple instances of a Swing component, only one at time. You can have multiple JTextAreas with the same Document, and

Get XY position from caret position in JTextArea

为君一笑 提交于 2019-12-22 10:44:17
问题 I'm trying to make an editor which have ability show pop up (JPopupMenu) each time users type any letter. Maybe, to imagine how my editor works its like any compiler, such as NetBeans when we type dot, the function appear. I have learned JPopupMenu from here. JPopupMenu needs XY position. My idea is to get XY position from JTextArea's caret position. My question is: Is there possible to get XY position from caret position (text cursor) in JTextArea or other JTextComponent? Or maybe is there

Enabling scroll bars when JTextArea exceeds certain amount of lines

余生长醉 提交于 2019-12-22 06:42:32
问题 this is my first time using any StackExchange website, so let's see how it goes. So I've been making a 'local' chat program in Java, and was using a JTextField for chat input. But I wanted to allow for multiline chatting so I switched to JTextArea. I'm using a GroupLayout (built with Window Builder Pro - eclipse) for easy window/component resizing. Here's a picture: The JTabbedPane, the JTextArea and the Send button are all contained in a JPanel, and all the stuff to the left is in it's own

How to Limit number of lines in JTextArea?

 ̄綄美尐妖づ 提交于 2019-12-22 04:55:09
问题 I am trying to make a GUI for a service, which have a JTextArea to view messages in, each message is written on a single line, and wordwrapped if needed. The messages arrive via a socket, so it is merely an .append(message) that i am using to update the JTextArea, i need to limit these lines to 50 or 100 and i have no need to limit character count on each line. If there is a method to limit the number lines in the JTextArea or if there is an alternative method of doing it? I could really use

How to select and retrieve a String of a whole line of text in a JtextArea?

拜拜、爱过 提交于 2019-12-21 12:29:37
问题 I have a JFrame that displays the current movies that are stored on my computer. It displays the names of the files as String s in a JTextArea . What I want to do is to double-click a particular String (which represents an actual file on my computer) and that file would be opened. The opening part and double-click part is already solved, but when I double-click on the String in my JTextArea only a part of that String will be selected. (I'm using JTextArea.getSelectedText() ). What I want is

JTextArea and JTextField internal padding on text

血红的双手。 提交于 2019-12-21 09:36:11
问题 I would like to increase the spacing / padding / insets for the JTextField and JTextArea. Effectively increase the spacing between the two red lines in the image below: 回答1: You could also try using an EmptyBorder to put in gaps between the two components. If you already have a Border, you can use that in conjunction with an EmptyBorder to create a CompoundBorder. In the code fragment below, a new CompoundBorder is created that has a TitledBorder and an EmptyBorder which enforces a padding of

Java - JPanel with margins and JTextArea inside

吃可爱长大的小学妹 提交于 2019-12-21 07:16:33
问题 I want to create something like this: Main panel has its margins (x), and TextArea in the center of that panel which almost fills up the panel. At the bottom is another panel with custom size (height y), which can be toggled visible and unvisible with some shortcut. Bottom Panel has FlowLayout and few elements. The problem is I have no idea how to do this. BoxLayout has no margins. I tried with GridBagLayout but I doesn't work or I can't understand it enough :( I tried also with setting

Creating custom swing component out of existing

為{幸葍}努か 提交于 2019-12-21 02:41:34
问题 So, I have this JTexrtArea which is almost perfect for my needs. The only thing wrong with it is the line spacing. I can't set it. (Why not JTextPane? Because spacing CAN be changed in JTextArea and JTextArea is way lighter thatn JTextPane, and I have a bunch of those in my program). I have asked this question before, and this is the answer that I got from user StanislavL: To override JTextArea's line spacing take a look at the PlainView (used to render PLainDocument). There are following

Line wrap in a JTextArea causes JScrollPane to missbehave with MiGLayout

佐手、 提交于 2019-12-21 02:33:06
问题 I am having trouble with the same thing as this guy: MigLayout JTextArea is not shrinking when used with linewrap=true and I used the solution described in one of the answers; to set the minimum size explicitly. This works fine if one places the JPanel which contains the JTextArea directly in a JFrame, and then resizes the window. However, when placing the panel which contains the JTextArea inside a JScrollPane, the same problem occurs again. Why is this, and how can one fix it? Cheers EDIT: