Hey everyone,

let me get straight to the point:
For my program I developed two custom classes that extend jPanel and have some text fields and check boxes in them.
(public class ServicePanel extends java.awt.Panel)

Now I've encountered three problems.

1. When add those panels to the GUI Palette and drag them into my main Form, the whole Layout window goes crazy. Little chunks of the imported panels go all over the place, flashing around, and I have to move my mouse over other objects to make the visible. This is annoying as hell, but at least things are fine when I compile.

2. I have a menu bar at the top of the Form. When I click on one of the menus at runtime, the menu opens perfectly. Only problem: If there is one of my custom panel classes in the way, it opens behind that panel. You can still see it a bit, but where it should be over the panel it just gets overlapped.
I also noticed that comboboxes in my custom panels don't open up, I assume that in fact they do, but just behind the panel.

3. An issue that is related to, but not caused by those panels: Assume the user types something into a textbox in a custom panel...how can I make the main form notice?

In other words: I want a class to Event-listen to Objects which got instantiated in another class.
Or, if this is not possible: I want the Object where the Event is happening to somehow adress the class it got instantiated by and do stuff there (invoke methods, change values, etc).

In the Java Docs and online I only found Event-Listeners for classes' own Objects...

While the first two problems may be caused by Netbeans or Java itself (Bugs), I'm sure the third one should be solvable quite easily, correct me if I'm wrong.

Thank you very much in advance for your answers!

azket

Okay, I solved problem number 2. It obviously was because my colleague used AWT Panels instead of Swing, which I didn't even notice as I copypasted the line into this topic.

Made them all JPanel, and now the menus work fine.

I also found a way for problem 3 by using something like this:
customPanel.comboBox.addItemListener(ItemListener il) {void ItemStateChanged(){return;};

Works fine until now, even though I'm not sure if it's the most elegant way.

Problem 1 to go!

It's a problem that occures with any custom panel I write, and the panels themselves work fine when compiled. It's just very hard to do the layout (pre-compile-time) in NetBean's GUI Builder, because there are custom Panels flashing all over the place.

I really can't see why this has something to do with my code, since the program works perfectly fine. It looks more like a NetBeans bug to me.
If it really is dependent on what I coded, please say so, and I will supply you (it's quite a lot of lines, thats why I ask).

But let me ask you another question:

If have a program with 30 custom textboxes, that extend JTextField.
I want a KeyListener on every single one of those boxes.

Do i really need to do it like this?

........
textBox1 = new DocumentPackage.TextBox();
textBox1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                textBoxKeyReleased();
            }
        });

textBox2 = new DocumentPackage.TextBox();
textBox2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                textBoxKeyReleased();
            }
        });

textBox3 = new DocumentPackage.TextBox();
textBox3.addKeyListener(new java......(...) {....} ....); ....

This would mean a massive amount of lines and a lot of typing.

Is it possible to add a KeyListener to the class TextBox itself, so that the TextBox objects somehow notify the class they got instantiated by about the typed key?

Maybe like the way it works with exceptions, so that TextBox just throws the information and the instantiating class can catch it and invoke methods itself...

I hope I could make myself clear.
Thanks,

azket.

This article has been dead for over six months. Start a new discussion instead.