简体   繁体   English

在 java 中制作可点击文本的最佳方法是什么?

[英]What is the best way to make clickable text in java?

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.我首先尝试使用没有所有边框/背景内容的 Jbutton,然后将 actionListener 连接到它,但我无法达到我认为它看起来不错的地步。 I also tried using a JLabel and hooking up a mouse listener to that but I also couldn't get it to look right.我还尝试使用 JLabel 并将鼠标侦听器连接到它,但我也无法让它看起来正确。

Basically I would like a way using swing to make a button exactly like a url link in an application.基本上我想要一种使用 swing 制作按钮的方法,该按钮与应用程序中的 url 链接完全相同。 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.您可能希望 go 更详细地了解“看起来不错”的含义。 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.我可以看到您通过 JButton 或 JLabel 解决此问题,但关键可能不是寻找其他解决方案,而是使用按钮或 label 的设置,直到它们看起来不错。 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.如果您找不到好的解决方案,请发布您的代码( SSCCE效果最好),也许我们可以帮助您。

that isn't answer to your question but are you tried to add ButtonModel to your JButton example here这不是您的问题的答案,但是您是否尝试在此处ButtonModel添加到您的JButton示例中

It is a rather heavy hammer to use, but SwingX has a JXHyperLink control that is probably exactly what you want.这是一个相当沉重的锤子,但 SwingX 有一个 JXHyperLink 控件,这可能正是您想要的。 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 .来源在http://java.net/projects/swingx/sources/svn/content/trunk/swingx-core/src/main/java/org/jdesktop/swingx/JXHyperlink.java?rev=402 and you can请参阅http://www.javalobby.org/java/forums/t18617.html上有关它的文章。

It is old, but SwingX continues to do good things.它已经过时了,但 SwingX 继续做好事。

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.您正在尝试在浏览器中创建一个看起来像 HTML 的桌面应用程序,您可以尝试在只读模式下使用一些更丰富的Swing 文本组件 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.您可以使用鼠标监听器来 map X/Y 点击文本的特定字符,然后在此基础上执行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用Java标记文本文件的最佳方法是什么? - What is the best way to tokenize a text file in Java? 在Java EE应用程序中同时进行httpurlconnection调用的最佳方法是什么 - What is the best way to make simultaneous httpurlconnection calls in a Java EE application Java - 从文件加载程序加载选项的最佳方法是什么? - Java - What is the best way to make a program load options from a file? 为Java软件制作美观的GUI的最佳方法是什么 - What is the best way to make a handsome GUI for a Java software 确保String可以作为int存储在java中的最佳方法是什么 - What is the best way to make sure a String can be stored as an int in java 从Java程序发出HTTP请求的最佳方法是什么? - What is the best way to make an HTTP request from a Java program? 在Java中在app引擎上制作blobstore实体副本的最佳方法是什么? - What is the best way make a copy of a blobstore entity on app engine in Java? 在Java中从Wikipedia转储搜索文本的最佳方法是什么? - What is the best way to search text from the Wikipedia dump in java? 将静态文本添加到Java Swing菜单的最佳方法是什么? - What's the best way to add static text to a Java Swing menu? 在 Java 中以字节为单位获取文本大小的最佳方法是什么? - What is the best way to get the size of text in bytes in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM