Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2005

Tip: Looking for answers? Try searching our database.

Problem Using NetBeans Visual Editor With User Defined Component

Thread view: 
MrFredBloggs@hotmail.com - 19 Jun 2005 06:51 GMT
Hi All,

I am using NetBeans 4.1 to design a small Swing application. Recently I
developed my own component by subclassing from JPanel. I have
successfully added this component to some of my dialogs and it displays
correctly in the visual editor design canvas. However I am unable to
use the editor to select any of the subcomponents within my panel (i.e.
buttons). I want to be able to attach events to these components.

Any ideas on what I am doing wrong?

Thanks,

Fred.
Andrew Thompson - 19 Jun 2005 06:54 GMT
> Any ideas on what I am doing wrong?

It is easier to see what you are doing wrong when you supply code.
<http://www.physci.org/codes/sscce.jsp>

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

MrFredBloggs@hotmail.com - 19 Jun 2005 07:06 GMT
Here is the code.

But first: It is intended that this panel would display a the bottom of
a dialog and contain a Cancel button and possibly another button which
I call the ActionButton. Below this is an area for a message. The
message displays for 2 seconds before reverting to some default
message. I have already designed several dialogs with a similar scheme
so I thought it a good idea to standardize it into my own component.

Regards,

Fred.

package com.dbuddies.mqface;

import java.awt.Color;
import java.awt.Toolkit;
import java.beans.*;
import java.io.Serializable;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class DCancelPanel extends JPanel implements Serializable
{
   private class Hint
   {
       private class Runner implements Runnable
       {
           private int    interval = 0;
           private String message  = "";

           private Runner()
           {
               super();
           }

           private void set(String stringIn, int intIn)
           {
               message  = stringIn;
               interval = intIn < 0 ? 0 : intIn;
           }

           public synchronized void run()
           {
               String previous = jLabelHint.getText();

               jLabelHint.setForeground(Color.RED);
               jLabelHint.setText(message);
               Toolkit.getDefaultToolkit().beep();

               try
               {
                   thread.sleep(interval);
               }
               catch (InterruptedException ie){}

               jLabelHint.setForeground(Color.BLACK);
               jLabelHint.setText(previous);
           }
       }

       Runner runner = null;
       Thread thread = null;

       private Hint()
       {
           super();

           runner = new Runner();
           thread = new Thread(runner);
       }

       private void flashHint(String stringIn, int intIn)
       {
           runner.set(stringIn, intIn);

           if (thread.isAlive())
               thread.interrupt();

           runner.set(stringIn, intIn);
           thread = new Thread(runner);
           thread.start();
       }
   }

   private PropertyChangeSupport propertySupport;

   private JButton jButtonCancel    = new JButton();
   private JButton jButtonAction    = null;
   private JPanel  jPanelInnerTop   = new JPanel();
   private JPanel  jPanelInnerBot   = new JPanel();
   private JLabel  jLabelHint       = new JLabel();
   private Hint    hinter           = null;

   public DCancelPanel()
   {
       super();

       propertySupport = new PropertyChangeSupport(this);

       this.initComponents();

       hinter = new Hint();
   }

   public void setActionButtonText(String stringIn)
   {
       jButtonAction = new JButton();
       jButtonAction.setText(stringIn);

       jPanelInnerTop.remove(jButtonCancel);
       jPanelInnerTop.add(jButtonAction);
       jPanelInnerTop.add(jButtonCancel);

   }

   public JButton getButtonCancel()
   {
       return jButtonCancel;
   }

   public void setCancelButtonText(String stringIn)
   {
       jButtonCancel.setText(stringIn);
   }

   public void setHintText(String stringIn)
   {
       jLabelHint.setText(stringIn);
   }

   public void flashHint(String stringIn)
   {
       hinter.flashHint(stringIn, 2000);
   }

   public void addPropertyChangeListener(PropertyChangeListener
listener)
   {
       propertySupport.addPropertyChangeListener(listener);
   }

   public void removePropertyChangeListener(PropertyChangeListener
listener)
   {
       propertySupport.removePropertyChangeListener(listener);
   }

   private void initComponents()
   {
       this.setLayout(new javax.swing.BoxLayout(this,
javax.swing.BoxLayout.Y_AXIS));

       jPanelInnerTop.setLayout(new
java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 10, 10));
       jPanelInnerBot.setLayout(new
java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 5));

       jButtonCancel.setText("Cancel");

       jPanelInnerTop.add(jButtonCancel);
       jPanelInnerBot.add(jLabelHint);

       this.add(jPanelInnerTop);
       this.add(jPanelInnerBot);

       jPanelInnerBot.setBackground(Color.WHITE);
       jLabelHint.setText("");
   }
}
Andrew Thompson - 19 Jun 2005 09:28 GMT
> Here is the code.

'the' code?  Or 'part of the' code?

Note that an SSCCE requires a self contained code sample,
the former, rather than the latter..

> But first:

...hmmmm?

>..It is intended ..

(snip)  None of this should matter if the example exhibits the problem.

> package com.dbuddies.mqface;

Now, the document I linked to advises that you remove the
package statements.  I am confident of that, since I wrote it.

Did you read the link?  All of it?

This is not an SSCCE, but let us count the ways..
Including a package statement is '1'.

> import java.awt.Color;
...

Compiled OK first attempt (*big* plus there), but
when I go to run it..

Exception in thread "main" java.lang.NoSuchMethodError: main

That is two (ways in which it is not an example that
is 'ready to go').  And my limit for the moment.

When you submit code, please add the extra attention and few
lines needed to make it a self contained example that is
ready to display the problem - exactly as copy/pasted
from the news client to a Java editor.  

Please review the SSCCE document carefully.
<http://www.physci.org/codes/sscce.jsp>
( and read all the way from the top to the bottom,
there are some subtle(?) messages in it! )

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Thomas Weidenfeller - 20 Jun 2005 08:50 GMT
> Any ideas on what I am doing wrong?

You (or NetBeans) are probably using the JavaBeans interface to add the
user-defined component. If you don't expose the needed function via
attributes, you don't have access to them. Any "bean handler", bean box,
etc. will never see your internal components, because a they are non of
their business.

Get the JavaBean specs., and also check the NetBeans documentation (if
they have some). Then implement the necessary methods.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.