简体   繁体   English

使String在TableModel中看起来像url

[英]Make String look like url in TableModel

Hello im making a program and using TableModel . 您好我正在制作一个程序并使用TableModel I have 6 column filed with string's. 我有6列用字符串提交。 I want the sixth column string make it look like URL. 我想要第六列字符串使它看起来像URL。 When i mean look like URL , i mean turn it into blue and be underlined. 当我的意思是看起来像URL,我的意思是把它变成蓝色并加下划线。 Is it possible to do that? 有可能吗?

You need to write custom TableCellRenderer for your jtable. 您需要为jtable编写自定义TableCellRenderer。 See this link .This may be helpful for you. 看到这个链接 。这可能对你有所帮助。

I'm pretty sure you can simply create a string containing 我很确定你可以简单地创建一个包含的字符串

<html>...</html> 

and it will work. 它会起作用。 Just code your link inside the html tags as you would in html. 只需在html代码中编写链接,就像在html中一样。 You'll just have to add extra code if you want it to appear blue. 如果您希望它显示为蓝色,则只需添加额外的代码。 I think: 我认为:

<font color='blue'>

would do it 会做的

Sun had a very good tutorial ( http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#modelchange ) on cerating jtable. 在cerating jtable上,Sun有一个非常好的教程( http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#modelchange )。 just go through it before you start. 在开始之前先完成它。 hope this tutorial will help you. 希望本教程能为您提供帮助。 But below is my suggestion. 但下面是我的建议。

("<html><b><u>link</u></html>");

<html><b><a href="link">bold</a></b></html>

a similar kind of thing 类似的事情

However, I wouldn't recommend altering the data in your model just to effect display. 但是,我不建议更改模型中的数据只是为了实现显示。 Instead I would create a custom cell renderer which accomplishes this effect and set it on the table. 相反,我会创建一个自定义单元格渲染器来完成此效果并将其设置在表格上。 You could either wrap your text in the HTML or manually set font color and style properties on the renderer to mimic html. 您可以在HTML中包装文本,也可以在渲染器上手动设置字体颜色和样式属性以模仿html。

Now even if you were to include the url in the html you still can't click on it. 现在,即使你在html中包含url,你仍然无法点击它。 There is no component in the table. 表中没有组件。 You don't really want to go into edit mode when clicking on a url. 点击网址时,您真的不想进入编辑模式。 You just want to open that link. 你只想打开那个链接。 To accomplish this you would add a mouse listener to the table itself. 为此,您需要向表本身添加一个鼠标侦听器。 When you receive a click event, you would then programatically determine which cell it was over, go back to your model and get the url, and finally use other Java API calls to open that url. 当您收到单击事件时,您将以编程方式确定它所在的单元格,返回到您的模型并获取该URL,最后使用其他Java API调用来打开该URL。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM