This is for an application so I don't want a hyperlink. I first tried using a Jbutton without all of border/background stuff and then hooking up an actionListener to it but I couldn't get it to the point where I thought it looked nice. I also tried using a JLabel and hooking up a mouse listener to that but I also couldn't get it to look right.
Basically I would like a way using swing to make a button exactly like a url link in an application. What is the standard way of doing this?
but I couldn't get it to the point where I thought it looked nice
You might want to go into greater detail on just what "looked nice" means. I can see you solving this by either a JButton or a JLabel, but the key is perhaps not to look for another solution but to play with the settings of the button or the label til they look nice. If you can't find a nice solution, then post your code (an SSCCE would work best of all) and perhaps we can help you.
that isn't answer to your question but are you tried to add ButtonModel to your JButton example here
It is a rather heavy hammer to use, but SwingX has a JXHyperLink control that is probably exactly what you want. The source is at http://java.net/projects/swingx/sources/svn/content/trunk/swingx-core/src/main/java/org/jdesktop/swingx/JXHyperlink.java?rev=4027 and you can see an article about it at http://www.javalobby.org/java/forums/t18617.html.
It is old, but SwingX continues to do good things.
It's you're trying to make a desktop application which looks like HTML inside a browser, you might try using some of the richer Swing text components in a read-only mode. You could use a mouse-listener to map X/Y clicks to a particular character of text, and then cause an action to occur on that basis.
Related
Which is the best way to make a window that has a name a JLabel and two JButton components underneath.
I am new to Swing and I tried some methods but didn't understood too much from any.
What would you suggest to focus my attention on to do this specific thing?
DYM like this?
Or this?
Actually that 2nd one comes from a page linked in the first comment.
But, you might be over complicating the issue and a JOptionPane might be a more suitable solution - see How to make dialogs for more details.
I have a JComboBox with an key listener.
When I hit <enter>, I fire off some action, and then I need to to lose focus on the JComboBox!
To focus on it, I can do JComboBoxObject.grabFocus();
But doing transferFocus() to get the focus to a next element (I don't care WHERE the focus goes, just away from combo box) does NOT work.
Doing grabFocus() from another combo box works, but seems like a pretty annoying hack to me. Is there a better solution?
I can suggest you to first use the
.getNextFocusableComponent()
and then use the
.requestFocusInWindow()
that means Implementing it like this,
JComboBox.getNextFocusableComponent().requestFocusInWindow();
One important note is that .getNextFocusableComponent() has become obsolete but it can work really better, you can use it but If you have any other solution, I would prefer not using this.
Updated: Starting from this two-combo example, adding either of these lines to the actionPerformed() implementation seems to do what you want.
combo1.transferFocus();
combo2.requestFocusInWindow();
I tried many methods to make a JButton such as the "Connect" button which appears in the digichat applet,
but I failed! Oh, I want know: What is the border type of this button? I attached a photo to explain the button; can any one help me with ideas, or tell me how to create it?
It may very well be a custom border, implemented entirely from scratch or a CompoundBorder which is a combination of several standard borders.
There's no way to tell how they have solved it based on the screen shot.
The appearance is defined by the old Mac OS 9 Look & Feel, as shown here:
Although it's a considerably more laborious alternative, you can implement your own ButtonUI, as illustrated here and here.
any one know how to change the label side of ChoiceGroup or TextField.( i mean default label come before the TextField. i need to bring label after the TextField)
sorry for my bad English i guess you guys understand the my problem.
there is no direct support in lcdui classes for your requirement, I would suggest try exploring LWUIT
Using standard controls is bad idea at all. Try to use CustomItem, third-party controls or create your own.
I need to create a drag and drop system in swing where an image of the thing being dragged is attached to the cursor during the drag. In theory this is achieveable with
public Icon TransferHandler.getVisualRepresentation(Transferable t)
but there appears to be a long standing bug (here) that means this method is never called. I know I can do it by implementing my own DnD system with DragSource etc., but does anyone know of an easier workround that will get me what I need?
The method TransferHandler.getVisualRepresentation wasn't supported in java 1.4, I'm not sure if or when it was fixed. To test whether it works in a current version you could adapt this example
In the end I used the old style drag-and-drop to implement what I wanted. However I have no reason to think abrightwell's solution wouldn't work just as well - this was just the best way at the time.
You could Try putting the image on a Jlabel (in the draggesture recognizer)and set its bounds, in the droptargetListener dragover method. Alternately, hows about implementing a Mouse listener (I've not tested this latter method).
I have used the "work around" suggested towards the bottom of the bug report you have listed. It worked well enough for me. Granted I was using this with Mac OS X so I have no idea whether Winderz will support it. It would be nice if they would at least fix it to work like they intended and simply document where it will and won't work... oh well. Good Luck.