using a TextField's functionality

i’d like to use the functionality of a TextField, but i want specify how to draw it and more important when. i don’t want to rely on AWT to do the job.

most games have all kinds of nice GUI stuff like ScrollPanes (but they don’t look like the do by default, of course), so how do they do it? do they write a new ScrollPane from scratch or do they use the functionality of an existing one and just rewrite the way it’s drawn?

hoping for an easy solution guys! :slight_smile:

EDIT: fixed some Jeff-writing

have you had a look at JTextField?
it might be possible using that.

Though you will be taking all the extra baggage of swing.

Its prolly best to start from scratch :stuck_out_tongue:

some1 needs to develop a LWGL (Light Weight GUI Library :D)

have you had a look at JTextField?

yup… but it flickers like crazy in fullscreen with BufferStrategy and i can’t get rid of it. i might be using it wrong, but i’ve tried all kinds of stuff. at first i thought it was that the doublebuffering of Swing was out of sync with the strategy, but setting doublebuffering to false on the JTextField didn’t do the trick.

any ideas?

Its prolly best to start from scratch

sigh, anyone does this before? is it hard? sounds boring :slight_smile:

can’t u just pass the bufferStrategys Graphics context into the paintComponent method?

I have to confess - i’ve never tried, maybe I should have a quick go :smiley:

if i use paintComponent, nothing is shown
if i use paint, it’s drawn at 0,0 all the time
if i use repaint, it flickers
if i use update, same result as paint

hah! i did a little hack:

JTextField textField = new JTextField(20);
nameField.setBounds(22, 82, 250, 30);
textField.paint(g.create(22, 82, 250, 30));

it works apart from the caret isn’t drawn… ah back to experimenting!

why not


Graphics g = getGraphics(); //or whereever your getting your Graphics context;
g.translate(x,y);
textComponent.paint(g);
g.translate(-x,-y);

yup, same thing :slight_smile:

i did another quick little hack:

DefaultCaret c = (DefaultCaret) textField.getCaret();
g.drawLine((int) c.getCenterX()-1, c.y, (int) c.getCenterX()-1, c.y + c.height);

this is very ugly and there must be another way, rigth?

haha lol

i forgot that the default color of the caret is black and i was using a black background :slight_smile:

i thought textField.setForeground(Color.WHITE); changed the caret as well, but it didn’t! a textField.setCaretColor(Color.WHITE); did the trick