/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
Focus on next component when tabbing insid~
Fra : Gunnar


Dato : 30-05-02 22:07

I wanted to focus on another component when I use the tab key in a JTextArea
(instead of tabbing inside the JTextArea).

This was not a problem. I did it by using setTabSize(0) and adding a
KeyListener to the JTextArea, that makes the next component grab focus when
the keyEvent = VK_TAB.

But when I AT THE SAME TIME set the linewrap in the JTextArea to true (like
this: textArea.setLineWrap(true)), I get a "divide-by-zero"-exception:

Exception occurred during event dispatching:

java.lang.ArithmeticException: / by zero

at javax.swing.text.WrappedPlainView.nextTabStop(Unknown Source)

at javax.swing.text.Utilities.getTabbedTextOffset(Unknown Source)

at javax.swing.text.Utilities.getTabbedTextOffset(Unknown Source)

at javax.swing.text.WrappedPlainView.calculateBreakPosition(Unknown Source)

at javax.swing.text.WrappedPlainView$WrappedLine.calculateLineCount(Unknown
Source)

at javax.swing.text.WrappedPlainView$WrappedLine.insertUpdate(Unknown
Source)

at javax.swing.text.WrappedPlainView.insertUpdate(Unknown Source)

at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(Unknown Source)

at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(Unknown
Source)

at javax.swing.text.AbstractDocument.fireInsertUpdate(Unknown Source)

at javax.swing.text.AbstractDocument.insertString(Unknown Source)

at javax.swing.text.JTextComponent.replaceSelection(Unknown Source)

at javax.swing.text.DefaultEditorKit$InsertTabAction.actionPerformed(Unknown
Source)

at javax.swing.SwingUtilities.notifyAction(Unknown Source)

at javax.swing.JComponent.processKeyBinding(Unknown Source)

at javax.swing.JComponent.processKeyBindings(Unknown Source)

at javax.swing.JComponent.processKeyEvent(Unknown Source)

at javax.swing.JTextArea.processKeyEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.processKeyEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)


Any help will make me a lot happier!

/Luffi





 
 
Gunnar (31-05-2002)
Kommentar
Fra : Gunnar


Dato : 31-05-02 16:52

Linda helped me out:


To transfer the focus from the JTextArea to the next component
with the Tab-key I overrode once processComponentKeyEvent in a
JTextArea subclass to do that (transferFocus();), which worked
then ok for me so far.


Linda
--
(=)
/ linda@jalice.ch - http://www.jalice.net
(=)
/ l.radecke@hswzfh.ch - http://www.hswzfh.ch
(=)

"Gunnar" <nogen@mail.dk> skrev i en meddelelse
news:3cf694a3$0$218$edfadb0f@dspool01.news.tele.dk...
> I wanted to focus on another component when I use the tab key in a
JTextArea
> (instead of tabbing inside the JTextArea).
>
> This was not a problem. I did it by using setTabSize(0) and adding a
> KeyListener to the JTextArea, that makes the next component grab focus
when
> the keyEvent = VK_TAB.
>
> But when I AT THE SAME TIME set the linewrap in the JTextArea to true
(like
> this: textArea.setLineWrap(true)), I get a "divide-by-zero"-exception:
>
> Exception occurred during event dispatching:
>
> java.lang.ArithmeticException: / by zero
>
> at javax.swing.text.WrappedPlainView.nextTabStop(Unknown Source)
>
> at javax.swing.text.Utilities.getTabbedTextOffset(Unknown Source)
>
> at javax.swing.text.Utilities.getTabbedTextOffset(Unknown Source)
>
> at javax.swing.text.WrappedPlainView.calculateBreakPosition(Unknown
Source)
>
> at
javax.swing.text.WrappedPlainView$WrappedLine.calculateLineCount(Unknown
> Source)
>
> at javax.swing.text.WrappedPlainView$WrappedLine.insertUpdate(Unknown
> Source)
>
> at javax.swing.text.WrappedPlainView.insertUpdate(Unknown Source)
>
> at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(Unknown
Source)
>
> at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(Unknown
> Source)
>
> at javax.swing.text.AbstractDocument.fireInsertUpdate(Unknown Source)
>
> at javax.swing.text.AbstractDocument.insertString(Unknown Source)
>
> at javax.swing.text.JTextComponent.replaceSelection(Unknown Source)
>
> at
javax.swing.text.DefaultEditorKit$InsertTabAction.actionPerformed(Unknown
> Source)
>
> at javax.swing.SwingUtilities.notifyAction(Unknown Source)
>
> at javax.swing.JComponent.processKeyBinding(Unknown Source)
>
> at javax.swing.JComponent.processKeyBindings(Unknown Source)
>
> at javax.swing.JComponent.processKeyEvent(Unknown Source)
>
> at javax.swing.JTextArea.processKeyEvent(Unknown Source)
>
> at java.awt.Component.processEvent(Unknown Source)
>
> at java.awt.Container.processEvent(Unknown Source)
>
> at java.awt.Component.dispatchEventImpl(Unknown Source)
>
> at java.awt.Container.dispatchEventImpl(Unknown Source)
>
> at java.awt.Component.dispatchEvent(Unknown Source)
>
> at java.awt.LightweightDispatcher.processKeyEvent(Unknown Source)
>
> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
>
> at java.awt.Container.dispatchEventImpl(Unknown Source)
>
> at java.awt.Window.dispatchEventImpl(Unknown Source)
>
> at java.awt.Component.dispatchEvent(Unknown Source)
>
> at java.awt.EventQueue.dispatchEvent(Unknown Source)
>
> at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
>
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
>
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
>
> at java.awt.EventDispatchThread.run(Unknown Source)
>
>
> Any help will make me a lot happier!
>
> /Luffi
>
>
>
>



Søg
Reklame
Statistik
Spørgsmål : 177501
Tips : 31968
Nyheder : 719565
Indlæg : 6408522
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste