[Bug] JBTextArea change its size after setting a new border attribute on focus listener

Answered

Hello :))))

I am facing a bizarre bug (let's hope this is a bug, not a feature 😅). 

I am using the focus listener in order to get the focus events (focus gained and focus lost) to be able to change the border style when the component gets focused. 

feedbackMessageField.addFocusListener(object : FocusListener{
override fun focusGained(e: FocusEvent?) {
feedbackMessageField.border = LineBorder(JBColor.BLUE, 2)
}

override fun focusLost(e: FocusEvent?) {
feedbackMessageField.border = LineBorder(JBColor.GRAY, 1)
}

})

So, I am currently using two fields, one is a regular JTextField another is this JBTextArea field. 

The problem is when I change the focus to the text area field (which has 4 lines), its layout becomes smaller, like one line only (I am attaching some pictures).

My layout is a GridBagLayout where I use some constraints to help me organize the dialog on the screen. I already tried also to use the jTextArea but found the same issue. 

The funny part tho: if I set a text or do something else in the listener event then nothing wrong happens 😅

0
1 comment

Hi Paula,

It's hard to tell what can be the reason without the full code.

Also, I don't know your use case, but changing the borders on focus in a custom way without an important reason is not a good idea. Custom dialogs and other components should be consistent with the rest of the IDE components. It may look strange to users that your dialog is the only one with custom focus behavior, while the rest doesn't do it.

If this is the case, I would avoid implementing it. Please also take a look at https://plugins.jetbrains.com/docs/intellij/plugin-user-experience.html

especially parts about consistency.

0

Please sign in to leave a comment.