Alexander Walker

Ranch Hand
+ Follow
since Jun 04, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alexander Walker

Martin Vajsar wrote:I didn't formulate my last paragraph well. I meant it as an enhancement to allow the users to change the key combination to enter the special character, ideally by pressing a key combination in a textbox or something similar. However you'd have to figure out how to record and later recognize a key event and bind the action to it. Probably even more work than the problem you've described first.


Okey, now I understand. I too think it will be more work than my original problem, but I still might do it, since it is good to have it.

And again thanks for all the help and suggestions I have recieved.
13 years ago

Martin Vajsar wrote:In this situation I'd probably try to use a key combination that would not collide with keyboard drivers, eg. Alt-E instead of AltGr-E. People that have the special character on their keyboard layout and are therefore used to it will be able to continue to use their natural key combination, and people that do not have it probably aren't used to a specific combination anyway and will have to learn your combination anew. Although entering characters with Alt-key is somewhat unusual, it is still much better than Copy-Paste.

Even if you'd succeed in overriding AltGr, it might present problems for someone with locale you didn't consider, who may have a different character on key combination you chose and who will not be able to enter that character because of your customization. Alt-key combinations are generally reserved for application use, so you should not encounter any collision with keyboard drivers. I'd expect Alt-key and Ctrl-key to be generally safe to use.

If your target platform is not solely Windows, you'll have to consult specific guidelines of other platforms. What I'm saying here is generally valid for Windows, but it might be different eg. on Unix or Mac - I don't know them. I have also no idea whatsoever how japanese or chinese haracters are typed on the keyboard, not even on Windows.


Thanks for the sugestion. This sounds like the best way to me, that way I want have to go through the same amount of trouble, and they will probably be more satisfied that way too.

Martin Vajsar wrote:
After all, it might be good idea to allow the users to enter the combination they want to use, especially if you target more platforms or platforms you cannot directly test - might need some work to implement the GUI for this, but will certainly satisfy everyone.


Did you mean that the users should be able to use what combinations they are used to, so it is better to use Alt-key or Crl+key? Or did you mean that the users should in the program be able to choose what combinations they want to have for the programs special keys?


Thanks for the help.
13 years ago

Martin Vajsar wrote:
the question is - what are you trying to achieve?


Basically I want to override some third-level characters (by third level characters I mean like you wrote, non-english characters, also explained in the AltGr wiki article). If you have a program where you have to enter a special character a lot of times, it will very fast become annoying if you on most of the keyboard localizations can't enter that special character, but instead have to copy-paste all of the time, hence why I wan't to overrirde a key combination. But because some keyboard localizations alreaddy have a special character associated to that key combination, I would need to cunsume it some way or else it will write two characters to the JTextField.

As for the key combinaitons I choose. On my keyboard localization when I press AltGr, then an action event with Ctrl-Alt seems to fired, however when I changed to US english keyboard localization an action event with Alt seems to be fired instead when I press AltGr. Hence I am confused as to what key combination I should use, that will feel natural for all keyboard localizations third-level characthers key combination.
If you have a recommendation as to what key combination I should use, please tell me.

Martin Vajsar wrote:
If you really want to intercept key events on such a low level, you'll probably have to study JTextComponent (parent of JTextField) and especially its processInputMethodEvent method. You may have to subclass the JTextField and override some methods, or register some InputMethodListeners.

This is just what I've learned from a quick peek into the javadoc and JTextComponent source code, I haven't done something like this myself. You'd be digging pretty deep into Swing so expect it will take some time to get familiar with these mechanisms. I've comparable experience with JTable, which I was extending to handle merged cells.


I will try looking into that, but it indeed sounds like it will be complicated and take time.

Thanks for the help.
13 years ago
I have a couple of problems I have encountered while making Key bindings.

1. When I make a key binding to for example Ctrl+Alt+E and have an action performed to write a character to the JTextField I was typing in, the character I programatically added will be added as it should, but if there was originally a character associated to that key combination, it will also be entered, meaning two characters will be entered while only one should be entered. Is there anyway to get rid of that character that was originally associated to that key combination?

2. When I type on my countries keyboard locale for example "Alt Graph+E", it seems that it is the same as typing "Ctrl+Alt+E", however when I type "Alt Graph+E" with the US English locale, it seems that it is the same as typing "Alt+E". Why is that? is there anyway for it to always be "Ctrl+Alt" when typing "Alt Graph" regardless of the keyboard locale? Well, for it to always actually fire "Alt Graph" when typing "Alt Graph" would also work.

Thanks in advance for any help.


Heres example code.
13 years ago

Rob Camick wrote:The Alt key is used to invoke the Windows System menu. Try "Alt" followed by the "Down arrow" key.


Thanks for the good answer. That answer question 2-4.

Rob Camick wrote:As a general rule you should be using Key Bindings and not listening for KeyEvents.


What is the reason that one should be using Key Bindings instead of a KeyListener?
13 years ago
I found some things when using a KeyListener that seems strange to me.

1. There is a InputEvent.ALT_GRAPH_DOWN_MASK that can be used to check if the Alt Graph is down, however whenever I press the Alt Graph key, the keyPressed method is called twice, first with Ctrl as the modifier and then with Ctrl+Alt as modifiers. Seems to me like it simulates Ctrl+Alt being pressed. Why even have a InputEvent.ALT_GRAPH_DOWN_MASK if it's never used? Or is it meant to be used with somthing else? Or is there something else that is the reason?

2. When presseing the Alt key twice in a row, the second time the keyPressed event is never fired. On the third time the method will be called again.

3. When pressing the Alt key once and then pressing the Ctrl key, then the keyPressed event is never fired no matter how many times you press it, but if you then press ONCE on the Alt key and then press the Ctrl key it will fire.
Key sequence example: Alt, Ctrl, Ctrl, Ctrl, Alt, Ctrl, Ctrl. The key pressed event for presesing the Ctrl will only be fired the two last times Ctrl is pressed. This probablöy have sometinh to do with 2. Seems to be the same if you do it with Shift or Caps lock too.

4. If I press the Alt key once and then press a letter key, then the keyPressed is not fired, however it will be fired if you press the letter once more.
Key sequence example: Alt, B, B, B. The keyPressed event is only fired the last two times when pressing the letter key B. This probably have someting to do with 2.


That was those things that I found, I hope I made any sense. I'd like to know if other peaple are also having the same problem, or is it just someting I have?


Heres is my code that can be run to check these things.
13 years ago

Rob Camick wrote:If not then maybe the approach used in the Screen Image class will help.



Thanks for the help. The approach used in the Screen Image worked great.
13 years ago
Hi,

I am trying to print an invisivle JTable that contains inner JTables (nested). The outer JTable prints as it should, but for some reason the inner JTables header is never printed, even though everything else of the inner JTables is printed as it should, and that is where the problem is. I have tried everything I can think of without solving it.

I would be happy if someone could help me with this.

Thatnks in advance for any help.

In my code the table is made visible after it is printed to show what it should be like.
Here's my example code:
13 years ago

Rob Prime wrote:

Alexander Walker wrote:

Maneesh Godbole wrote:Why reinvent the wheel?
Check out the various JOptionaPane.showXXXDialog() methods


As far as I know JOptionPane.showXXXDialog() only works on questions, and it is not something that you can modify as you wish, like you can with a JDialog or JFrame. Like adding many buttons or textfields and/or different containers.


Sure it is. The message object doesn't need to be a String. It can be:
- an Icon -- a label with the icon will be added.
- a Component -- the component itself will be added. This component can be a simple component like a JTextField, or a full GUI on its own.
- an Object[] -- each element will be added separately.
- anything else -- the string value will be added as one or more labels, depending on the number of line breaks.

So yes, adding containers is quite possible indeed.


Maneesh Godbole wrote:
If you look at the API, you will notice those methods accept an Object message.
You can always construct your panel, put in all the UI components on it and pass the panel as the message to the method.


I did'nt know you could do it like that. Thanks for the good faqt.


Rob Prime wrote:

pete stein wrote:
but myself I'd prefer not to extend JFrame or JDialog if I'm not altering their intrinsic behavior.


Is there any disadvantage with extending JFrame or JDialog, or is it only a personal preference? Good to know for future reference .


It's a bad object oriented approach. Your dialog doesn't add any behaviour or anything. Instead you should just use a regular JFrame or JDialog to which you add the rest of the GUI. So instead of your class being a JFrame or JDialog, it uses one.

But I must admit, I go the lazy way myself all too often and just extend.


I see, that is good to know. Good explanations too.

I almost did'nt notice that small text
13 years ago
Thanks Rob that worked great

Maneesh Godbole wrote:Why reinvent the wheel?
Check out the various JOptionaPane.showXXXDialog() methods


As far as I know JOptionPane.showXXXDialog() only works on questions, and it is not something that you can modify as you wish, like you can with a JDialog or JFrame. Like adding many buttons or textfields and/or different containers.

pete stein wrote:
but myself I'd prefer not to extend JFrame or JDialog if I'm not altering their intrinsic behavior.


Is there any disadvantage with extending JFrame or JDialog, or is it only a personal preference? Good to know for future reference .
13 years ago
Hi

I have JFrame with a JButton, and when clicked it opens up a new JDialog with a JTextField with some text in it. When this JDialog is closed, the text in the text field is erased, however when the JDialog is opened again, the old text that was erased flicker (only for an instant, if you look closely). I'd like to know if there is any way fix this. Do note that it is not something that happens all the time. It usually happens the first try for me, but it should'nt take many trys even if it does'nt.

Thanks in advance for any help.


Heres the example code (used a big font because it is easier to see that way):

13 years ago
I was able to solve the problem by myself, and will share it here. I have done a new program, and nothing is taken from Sun's example. The content of the method is a modified version of java2s.com's Set column width based on cell renderer, if I remember right. As far as I know this is not copyrighted code, atleast I coud'nt find anything about it. If anyone have a different opinion, then please tell me, and I will remove the code.

Heres the code:

13 years ago

Darryl Burke wrote:Is it legal to post copyright code on a public forum?



If it is not, then I am sorry, and will remove the code, until someone gives me permission. Though I personally think I did do as the copyright stated, but it is up to the moderators to decide. I will remove the code until someone tells me it is okay. Just to let others know who read this later, it was code of Sun's JTable Printing example that was modified. I did keep the copyrighted text, so I never claimed it to be my own.

I'm sorry if I did something I should'nt have done.
13 years ago
My JTable is a table with some columns including a checkbox column. When the user clicks on the print button, the program will create an invisible copy of the visible table, then add a rowsorter to exclude all the rows with a checkbox that is set to false. then remove the checkbox column from the table. For the table to print I manually change the size of the table (else the content will not print).
That is how I set up the table, I hope it made sense.

But it is when I set the table to print with JTable.PrintMode.FIT_WIDTH thats not working as it should. The table is not printed across the whole page, like it still believes that the removed column is still there, resulting in that the rigthmost column will be cut, and not all data will be printed. I don't have this problem when printing JTable.PrintMode.NORMAL.
I hope my explanation made sense.

I have tried a long time to fix this but without result.
I'd be gratefull if someone could help me.


Here is the code.

edit: I have removed the code till someone who knows tells me it is okay (see the two posts below).
13 years ago
It was'nt exactly impossible, and it was'nt that hard to do either once I started thinking a bit about it. In my solution I just added a MouseMotionListener to my outer table, that programatically entered edit mode when the mouse was above a cell in column 0 or 1, since they contained the nested table.

Here is my solution for those who want it.

13 years ago