This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Customed JButton text cannot be seen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Customed JButton text cannot be seen" Watch "Customed JButton text cannot be seen" New topic
Author

Customed JButton text cannot be seen

Jes Sie
Ranch Hand

Joined: Jul 24, 2001
Posts: 188
Hi,
I'm fairly new with Swing stuff. I'm in the midst of extending a JButton. The behaviour and look&feel works except that his face value/text cannot be seen.
Below is the code. Anyone care to check it out please?
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
/**
* This button is meant to assist configuration of Rules or Conditions.
*/
public class InvisibleButton extends JButton implements ActionListener
{
protected Border activeBorder;
protected Border inactiveBorder;
protected String text;
protected String sUrl;
protected URL url;
// to store a lightwieght Condition or Rule
protected Object anObject;
public InvisibleButton( String atext, String sUrl)
{
setText(atext);
sUrl = sUrl;
try
{
url = new URL(sUrl);
}
catch(Exception ex) { url = null; }
setOpaque(false);
activeBorder = new MatteBorder(1, 1, 1, 1, Color.yellow);
activeBorder = new MatteBorder(1, 1, 1, 1, Color.yellow);
inactiveBorder = new EmptyBorder(1, 1, 1, 1);
setBorder(inactiveBorder);
addActionListener(this);
}
public void setText(String atext)
{
text = atext;
super.setText(""+atext+"");
setToolTipText(atext);
}
public String getText()
{
return text;
}
protected void processMouseEvent(MouseEvent evt)
{
switch (evt.getID())
{
case MouseEvent.MOUSE_ENTERED:
setBorder(activeBorder);
setCursor(Cursor.getPredefinedCursor(
Cursor.HAND_CURSOR));
break;
case MouseEvent.MOUSE_EXITED:
setBorder(inactiveBorder);
setCursor(Cursor.getPredefinedCursor(
Cursor.DEFAULT_CURSOR));
break;
}
super.processMouseEvent(evt);
}
public void actionPerformed(ActionEvent e)
{
if (url != null)
{
// Do lotsa stuff
}
}
public void paintComponent(Graphics g)
{
paintBorder(g);
}
}


------------------
Thank you.
- Simon See
simon-ivy@usa.net
-after office hours-
necro-mani-cide


Thank you.<br /> <br />- Jess Sie<br /> <a href="mailto:jess@see-consulting.com" rel="nofollow">jess@see-consulting.com</a>
Matt Hansen
Ranch Hand

Joined: Jul 31, 2001
Posts: 34
In your paintComponent you only paint the border and not the compenent. Try adding this to paintComponent.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Customed JButton text cannot be seen
 
Similar Threads
How to DnD JLabels in left Jpanel to right and vice versa??
Displaying pdf and rtf files
FTPProtocolException:STOR and FTPProtocolException:LIST??
Problem with FTPClient??
Why I cannot Move my JLabel after I add SetToolTipText()??