
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
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