• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is, I can't use a JTextField. Those are the teacher instructions.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This would fit better in our GUIs forum. Moving discussion.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And if I use a JTextArea?
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Crossposted: http://stackoverflow.com/questions/29787928/how-to-make-a-grid-for-a-crossword-user-writable
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic