This content has been marked as final.
Show 3 replies
-
1. Re: Modifying jcomponent
chiba Jul 26, 2004 7:42 AM (in response to gordon1986)This problem should have been fixed in CVS_HEAD.
Please download the source files from CVS and try again.
At least, I could run the following code without any problem:ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.get("javax.swing.JComponent"); CtMethod m = cc.getDeclaredMethod("paint"); m.insertBefore("((java.awt.Graphics2D)$1).setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);"); Class c = cc.toClass(); // I added.
-
2. Re: Modifying jcomponent
gordon1986 Jul 26, 2004 9:52 AM (in response to gordon1986)
Well, now I get errors:javassist.CannotCompileException: by java.lang.LinkageError: duplicate class definition: javax/swing/JLabel at javassist.CtClass.toClass(CtClass.java:900) at javassist.CtClass.toClass(CtClass.java:860) at AASwing.main(AASwing.java:40) Exception in thread "main"
The exception is thrown at the Class c = cc.toClass(); line.
the code is as follows:ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.get("javax.swing.JLabel"); CtMethod m = cc.getSuperclass().getDeclaredMethod("paint"); m.insertBefore("((java.awt.Graphics2D)$1).setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON); super.paint($1);"); Class c = cc.toClass(); JLabel b = (JLabel)c.newInstance();
How do I replace the JLabel component? -
3. Re: Modifying jcomponent
chiba Jul 27, 2004 7:27 AM (in response to gordon1986)That's because the JVM had loaded JLabel
before toClass() was called. To avoid this,
maybe you should write your own class
loader to run your whole application.
For details, please take a look at the tutorial.