1 2 Previous Next 28 Replies Latest reply: Dec 6, 2006 3:33 PM by 807607 Go to original post RSS
      • 15. Re: Casting a Component as JTextComponent
        807607
        Fine! makes pouting face

        Also, I may have inserted it in an edit while u were responding, but I posted the class that makes sure they are all JTextComponents (getComponentsByTypeFromTree), so that should prove it too.

        inserting
        System.err.println(Arrays.deepToString(allJTextComponents));
        right after the allJTextComponents assignment prints thus:
        [javax.swing.JFormattedTextField[Spinner.formattedTextField,0,0,23x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=RIGHT], javax.swing.JTextField[,1,1,26x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,31,1,26x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,61,1,26x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,91,1,26x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,1,1,26x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,31,1,26x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,61,1,26x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,91,1,26x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,1,1,26x17,invalid,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,31,1,26x17,invalid,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,61,1,26x17,invalid,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JTextField[,91,1,26x17,invalid,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=3,columnWidth=8,command=,horizontalAlignment=CENTER], javax.swing.JPasswordField[,294,97,43x19,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=4,columnWidth=8,command=,horizontalAlignment=LEADING,echoChar=*], javax.swing.JFormattedTextField[Spinner.formattedTextField,0,0,39x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=6,columnWidth=8,command=,horizontalAlignment=RIGHT], javax.swing.JFormattedTextField[Spinner.formattedTextField,0,0,39x17,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=6,columnWidth=0,command=,horizontalAlignment=RIGHT], javax.swing.JPasswordField[,122,128,115x19,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=5,bottom=2,right=4],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=13,columnWidth=8,command=,horizontalAlignment=LEADING,echoChar=*], javax.swing.JPasswordField[,0,0,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,26,0,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,52,0,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,78,0,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,104,0,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,130,0,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,156,0,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,182,0,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,0,26,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,26,26,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,52,26,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,78,26,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,104,26,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,130,26,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,156,26,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,182,26,21x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,0,52,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,26,52,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,52,52,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,78,52,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,104,52,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,130,52,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,156,52,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,182,52,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,0,78,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,26,78,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,52,78,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidth=8,command=,horizontalAlignment=CENTER,echoChar=*], javax.swing.JPasswordField[,78,78,21x21,disabled,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.sun.java.swing.plaf.windows.XPStyle$XPFillBorder@12922f6,flags=296,maximumSize=java.awt.Dimension[width=4,height=19],minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=172,g=168,b=153],editable=true,margin=java.awt.Insets[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=49,g=106,b=197],columns=2,columnWidt
        • 16. Re: Casting a Component as JTextComponent
          796440
          What I meant was this.

          You're doing something like this, right?
          ((JTextComponent)thingy).someJTextComponentMethod();
          And that line is giving CCE?

          So, right before that line, add
          System.out.println(thingy.getClass());
          And tell us what class comes out in the case when you get the CCE.
          • 17. Re: Casting a Component as JTextComponent
            807607
            Ah, can do.

            It looks like I missed one of those components so the page is reeeeeaaly wide now. If you guys are admins could u fix that line, or just delete that post? thnx

            The new
                    JTextComponent[] enabledTextComponents;
                    {
                        JTextComponent[] allJTextComponents =
                                Components.getComponentsByTypeFromTree(
                                        JTextComponent.class,this);
                        System.err.println(allJTextComponents.getClass());
                        enabledTextComponents =
                                Components.getEnabled(allJTextComponents);
                    }
            prints class [Ljavax.swing.text.JTextComponent;

            interesting... this throws a CCE:
            System.err.println(Components.getEnabled(allJTextComponents).getClass());
            but
            System.err.println(Components.getEnabled(allJTextComponents)); 
            prints a Component array, plus its hash code. I suppose that makes sense because the erasure of the return type is a component array <T extends Component> T[]

            I think this is the problem... but what do i do about it?

            Message was edited by:
            MutantPlatypus
            • 18. Re: Casting a Component as JTextComponent
              807607
              I didnt really read this thread too carefully but if you have an array of Components and you want to find which are actually JTextComponents perhaps you can try something like:
              if( object instanceof JTextComponent.class ){ }
              http://mindprod.com/jgloss/instanceof.html
              • 19. Re: Casting a Component as JTextComponent
                796440
                interesting... this throws a
                CCE:
                System.err.println(Components.getEnabled(all
                JTextComponents).getClass());
                but
                System.err.println(Components.getEnabled(allJTextCompo
                nents)); 
                prints a Component array,
                plus its hash code. I suppose that makes sense
                because the erasure of the return type is a component
                array <T extends Component> T[]
                The erasure is Component[], true. However, the compile-time T requires either JTextComponent[] or something. I'm not sure how this all fits togehter. Try printing the class of the array. It might be that it's
                actually a JTextComponent array and you've put
                something else into it, or it might be that it's a
                Component array, but, .... well, I don't know.

                I'm not that conversant with the subtleties of
                generics, but I suspect you're abusing something
                here.

                public static <T extends Component> T[] getEnabled(final T... comps)
                Print out the whole stack trace. It should tell you something about what class it's trying to cast from or
                to, and print out the class of the array.

                Message was edited by:
                jverd
                • 20. Re: Casting a Component as JTextComponent
                  807607
                  OK, to illustrate this better:
                  JTextComponent[] enabledTextComponents;
                  {
                      JTextComponent[] allJTextComponents = Components.getComponentsByTypeFromTree(JTextComponent.class,this);
                      Component[] someComps = Components.getEnabled(allJTextComponents);
                      enabledTextComponents = (JTextComponent[])someComps;   //<-ClassCastException is thrown here
                  }
                  And, if u look at the previous posts, in theory (getComponentsByTypeFromTree) and in practice (printing the entire contents of the array), the Component array does indeed only contain JTextComponents.
                  • 21. Re: Casting a Component as JTextComponent
                    796440
                    I can't see enough of what's going on at once, nor do I understand
                    your overall goals well enough, to be able to say what's going on.

                    Try printing the class of the array and looking closely at the stack trace
                    for clues like I said.

                    But if you have T[], where <T extends Component>, you don't have a JTextComponent[]. It's just a Component[].
                    Casting that to JTextComponent[] won't work.
                    • 22. Re: Casting a Component as JTextComponent
                      796440
                      JTextComponent[] enabledTextComponents;
                      {
                      JTextComponent[] allJTextComponents =
                      Components.getComponentsByTypeFromTree(JTextComponent
                      class,this);
                      Component[] someComps =
                      Components.getEnabled(allJTextComponents);
                      enabledTextComponents =
                      (JTextComponent[])someComps;
                      //<-ClassCastException is thrown here
                      See reply 1.

                      If you can't make whatever you're trying to accomplish
                      (and I still don't now what that is) work with generics,
                      or even if you can but it's complex, then just do the
                      array copy. It's one extra line of code. There can't be
                      that many components, so it will be fast. (You're just
                      copying references, not cloning objects.)
                      • 23. Re: Casting a Component as JTextComponent
                        807607
                        But if you have T[], where <T extends Component>, you
                        don't have a JTextComponent[]. It's just a
                        Component[]. Casting that to JTextComponent[] won't
                        work.
                        That is exactly what I'm trying to do. I have an array of Component, I know its really an array of JTextComponent, and I want to treat it like such. The only way I can think of to call a JTextComponent method would be through Method.invoke, but I'm wondering if there's a way to do it without that (and actually get an array of JTextComponent)

                        What am I looking for in the stack trace? The line I labled as throwing the class cast exception is the bottom of the stack trace, and from there it goes right up the typical awt invocation chain.

                        Thanks for your continued help.

                        P.S. I tried changing all <T> to <Object> and <T extends Component> to just <T> and I still get a class cast exception when trying to cast it to a JTextComponent. My next post will be the entire classes, because I'm getting to the end of my rope here.

                        EDIT:
                        OK, i'll try arraycopy

                        Message was edited by:
                        MutantPlatypus
                        • 24. Re: Casting a Component as JTextComponent
                          807607
                          I don't know how that works without throwing an ArrayStoreException, but it works! Thanks.
                                  JTextComponent[] enabledTextComponents;
                                  {
                                      JTextComponent[] allJTextComponents =
                                              Components.getComponentsByTypeFromTree(
                                                      JTextComponent.class,this);
                                      
                                      Component[] enabledTextComponentsAsComponents =
                                              Components.getEnabled(allJTextComponents);
                             
                                      JTextComponent[] enabledTextComponents0 =
                                              new JTextComponent[
                                                      enabledTextComponentsAsComponents.length
                                              ]
                                      ;
                                      
                                      System.arraycopy(enabledTextComponentsAsComponents, 0,
                                              enabledTextComponents0, 0,
                                              enabledTextComponents0.length);
                                      
                                      enabledTextComponents = enabledTextComponents0;
                                  }
                          • 25. Re: Casting a Component as JTextComponent
                            796440
                            But if you have T[], where <T extends Component>,
                            you
                            don't have a JTextComponent[]. It's just a
                            Component[]. Casting that to JTextComponent[]
                            won't
                            work.
                            That is exactly what I'm trying to do.
                            Like I told you, and like the CCE is telling you, you can't do that.

                            I have an
                            array of Component, I know its really an array of
                            JTextComponent,
                            No. It's an array of Component that happens to contain only JTC.
                            There's a significant difference.

                            Why not just use System.arraycopy to create an array of
                            JTextComponent? Or just cast each one at the point you try to do
                            JTextComponent things to it? Or change the other method so that it
                            returns JTC[]?


                            wondering if there's a way to do it without that
                            (and actually get an array of JTextComponent)
                            >
                            What am I looking for in the stack trace?
                            That was to try to figure out why you were getting the CCE. Now it's
                            obvious--you're casting C[] to JTC[].
                            The line I
                            labled as throwing the class cast exception is the
                            bottom of the stack trace,
                            Yeah, you'd look at that first line to see what class you're casting from.
                            Then you can know why the cast failed. But now that I see what you're
                            doing, we know what the cause is.



                            >
                            P.S. I tried changing all <T> to <Object> and <T
                            extends Component> to just <T> and I still get a
                            class cast exception when trying to cast it to a
                            JTextComponent.
                            Wait. That's very different. Casting JTC or to JTC[]? You said JTC earlier
                            too, and that's why I got confused about the CCE. But if you've always
                            been casting to JTC[], then no, generics won't help you. It's an erasure
                            to C[], so C[] is what you have at runtime, and there's no way to cast
                            that to JTC[].
                            • 26. Re: Casting a Component as JTextComponent
                              796440
                              I don't know how that works without throwing an
                              ArrayStoreException,
                              Because every element of the source array is of the appropriate
                              type for the dest array.

                              If one of the elements in the C[] source array was some other non-JTC component, you'd get the exception.
                              • 27. Re: Casting a Component as JTextComponent
                                807607
                                Its a good workaround, but do you know how to do it with generics, or someone who might?
                                • 28. Re: Casting a Component as JTextComponent
                                  796440
                                  I don't know if you can do what you want w/ generics, but I think
                                  there's a Generics section at this forum.

                                  If you post there, post a link back to this thread, so people can get the detailed background if they want.
                                  1 2 Previous Next