Search code examples
javaswinguser-interfacejtextfield

Drawing a text field without the use of JTextField etc


I'm making a launcher for a game I'm developing and I use Graphics2D to render buttons, gui etc. Now I've extended the class that does this (Launcher.java) with the Canvas. This means I can't use JTextFields (plus it would look ugly anyway). So my question is, how would I make a text field without the use of JTextField, this means rendering it, getting key input display the input. Thanks.


Solution

  • You state: I'm making a launcher for a game I'm developing and I use Graphics2D to render buttons, gui etc.

    You seem to be re-inventing the wheel. Why not instead use or create a Look and Feel that works well.

    You state: Now I've extended the class that does this (Launcher.java) with the Canvas.

    By committing to AWT components you are unnecessarily limiting what you can do. Why not just stick with Swing components?

    You state: This means I can't use JTextFields

    You can if you stick with Swing.

    You state: (plus it would look ugly anyway).

    Without images, it's hard to discuss this point.

    You state: So my question is, how would I make a text field without the use of JTextField, this means rendering it, getting key input display the input.

    Again, why commit to re-invent the wheel? Use Swing components including JTextFields, avoid AWT, and if you still feel the GUI is ugly, consider posting images and a small compilable and runnable program that we can mess with and that shows us directly your problem.