Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make a grid for a crossword, user writable?  RSS feed

 
fredy salgado
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been reading that there's no way of making a JLabel user writable. What can I use inside the grid to make it writable with a keylistener?

*I'm making a crossword.
 
Carey Brown
Saloon Keeper
Posts: 2537
33
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextField.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you use a JTextField, you can use ordinary techniques instead of having to mess around with low-level techniques like key listeners.
 
fredy salgado
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is, I can't use a JTextField. Those are the teacher instructions.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose you could try using a JLabel and attaching a key listener to it, and changing the JLabel based on whichever key was pressed. But I have to say I have very little sympathy with homework assignments which deliberately make you choose bad ways of doing things.
 
Campbell Ritchie
Sheriff
Posts: 53769
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would fit better in our GUIs forum. Moving discussion.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fredy salgado wrote:The problem is, I can't use a JTextField. Those are the teacher instructions.

Well then you can use a JComboBox or a JSpinner . If you tell us what exactly your teacher instructed you, we can perhaps offer better ideas.
 
fredy salgado
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the only condition inside the crossword grid, to not use a jtextfield.


 
fredy salgado
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if I use a JTextArea?
 
Campbell Ritchie
Sheriff
Posts: 53769
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. Go through the Java® Tutorials, and you will get an explanation of the different kinds of text components.
 
Piet Souris
Rancher
Posts: 1783
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP
What is it that you have in mind? At first I thought you wanted to create a JPanel
with a gridlayout, N x M in size. Well, to me that is what I would expect
from a GUI representing a crossword puzzle.

If that is indeed the goal, then I fail to see how you would achieve this by using
a textfield, or a textarea. Maybe you, or other people that suggested similar,
can explain that to me.

My advice is what I already wrote above. In each cell of the grid, you place a JLabel.
Attach a mouselistener to each label, its only task being to register which label
has the so called 'input focus'.

To the panel, attach a keylistener. When a key is typed, put the text of the 'input
focus' jlabel equal to the key. If arrow keys are typed, then adjust the input focus
label.

Unwritable labels are excluded from above. No mouse listener, unable to
gain the input focus, and with a black or so background.

This is the easiest I can think of.

Greetz,
Piet
 
Rob Camick
Ranch Hand
Posts: 2754
12
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!