JTextField not responding to certain keycommands

Hi, I have a small problem.
I have a custom ConsoleView that I also want to put a JTextField and some buttons into to the far right. I do it like this:

consoleView.getComponent().add(commField.getPanel1(), BorderLayout.EAST);

Everything looks fine. The problem is that I cant use the arrow keys to move the caret around in the textfield. I can enter ordinary characters like "abc..." but anything else like etc. the DEL key does not work.

Is Intellij overriding those keys in some way? How can I get them to work in this component?

8 comments

Ok, let me rephrase the question.

How can I get a multiline textfield in a toolwindow?

0

Johan Lund wrote:

How can I get a multiline textfield in a toolwindow?


You could consider using the class com.intellij.ui.EditorTextField. It's not
part of the OpenAPI, but it's pretty straightforward to use.

Sascha

0

Sounds good, but Intellij can't find it. Do I need to reference some jars or something?

0

Have you added idea.jar to your IDEA SDK?


0

No. :)
Now it works. But how do I add it to the ConsoleView?
I tried adding it like this:

EditorTextField tf = new EditorTextField("hello");
consoleView.getComponent().add(tf.getComponent(), BorderLayout.EAST);

The toolwindow only opens half way and I get this exception:

com.intellij.openapi.editor.impl.EditorImpl
java.lang.ClassCastException: com.intellij.openapi.editor.impl.EditorImpl
at com.intellij.ui.EditorTextField.createEditor(EditorTextField.java:119)
at com.intellij.ui.EditorTextField.addNotify(EditorTextField.java:144)
at java.awt.Container.addNotify(Container.java:2500)
at javax.swing.JComponent.addNotify(JComponent.java:4478)
at java.awt.Container.addNotify(Container.java:2500)
at javax.swing.JComponent.addNotify(JComponent.java:4478)
at java.awt.Container.addNotify(Container.java:2500)
at javax.swing.JComponent.addNotify(JComponent.java:4478)
at java.awt.Container.addNotify(Container.java:2500)
at javax.swing.JComponent.addNotify(JComponent.java:4478)
at java.awt.Container.addImpl(Container.java:1052)
at java.awt.Container.add(Container.java:351)
at com.intellij.openapi.ui.ThreeComponentsSplitter.setLastComponent(ThreeComponentsSplitter.java:330)
at com.intellij.openapi.wm.impl.ToolWindowsPane.a(ToolWindowsPane.java:33)
at com.intellij.openapi.wm.impl.ToolWindowsPane.access$100(ToolWindowsPane.java:42)
at com.intellij.openapi.wm.impl.ToolWindowsPane$AddDockedComponentCmd.run(ToolWindowsPane.java:17)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:10)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:8)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:72)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:73)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

0

Ok, if I put it inside a JPanel I don't get the exception but the control is empty. There does not seem to be an editor in there. Any idea?

0

Johan Lund wrote:

No. :)
Now it works. But how do I add it to the ConsoleView?


Do you mean com.intellij.execution.ui.ConsoleView? This is a component that
already contains an Editor-instance that allows the display (and AFAIK also the
input) of text. I don't think you're supposed to add anything to this component.

I tried adding it like this:

EditorTextField tf = new EditorTextField("hello");
consoleView.getComponent().add(tf.getComponent(), BorderLayout.EAST);

The toolwindow only opens half way and I get this exception:

com.intellij.openapi.editor.impl.EditorImpl
java.lang.ClassCastException: com.intellij.openapi.editor.impl.EditorImpl
at com.intellij.ui.EditorTextField.createEditor(EditorTextField.java:119)


That looks strange. I'd say something in your project setup is broken. You
should check that you added idea.jar to the IDEA-JDK, not as a regular library.
Also make sure that idea.jar and/or openapi.jar isn't in your (deployed)
plugin's lib folder.

Sascha

0

Found the original problem.
The ConsoleView component did not like the company of the JTextArea to the east. But if I put both components inside a new "mother" panel everything suddenly works.

Thanks for helping out though Sascha. Much appreciated...

0

Please sign in to leave a comment.