Make String look like url in TableModel - java

Hello im making a program and using TableModel. I have 6 column filed with string's. I want the sixth column string make it look like URL. When i mean look like URL , i mean turn it into blue and be underlined. Is it possible to do that?

You need to write custom TableCellRenderer for your jtable. See this link.This may be helpful for you.

Sun had a very good tutorial (http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#modelchange) on cerating jtable. 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>bold</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.
Now even if you were to include the url in the html you still can't click on it. 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.

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. You'll just have to add extra code if you want it to appear blue. I think:
<font color='blue'>
would do it

Related

Java Thumbnail View

Hey i want to create a thumbnail viewer, for my app, i want something similar to this.
I was wondering if there is a pre-existing component that can display thumbnails (FREE), or i was considering to use a JTable, with a custom cell renderer.
What do you think, what would be the best way.
It will be used to display images, keep in mind that i must be able to select individual and multiple files to perform actions on them.
thx in advance.
A JList would probably be better than a JTable. You can use a "horizontal wrap" style. You can always create a custom renderer for the list as well.

Drag and Drop through html table and Swing?

Is it possible to drag and drop some table from a web page and get the same table structure on a JTable?
You'll want to implement a DropTargetListener on the swing component you want to drag the HTML into. Then get the HTML from the drag using a text/html DataFlavor, and parse the HTML, converting it into a TableModel. Set this TableModel on your JTable.
I rode it is possible to Drag n Drop from desktop to browser, but not the other way around.
So, i don't know the answer to your question, but i would mention a little idea came to mind, maybe you find interesting:
Not directly dragging the table to the swing app. Instead drag that table from the browser, to some textArea or image on the page. It could then automatically transform the tabellar data to XML start some stream that sends that data to your swing application(Maybe some webservice could do pass it to the desktop app).
I don't know if that can help you giving you some tips, other thing comes to my mind is the dropbox API for java, check it out, maybe you have some interesting features that can help you.

JEditPane inside another JEditPane in swings(java)

I've a JEditPane "jep" to write in it like a document..
I want to add another JEditPane inside this 'jep'. is it possible to add? if so how? Please help me..
Below is an image showing the requirement. The whole image is JEditPane, on the leftside i need another box(yellow box in image) which i can write someting in it (like EditPane).. please give some hints.. thank you..
A JLayeredPane with the jep in the lowest (back-most) layer would allow you to float the other JEditorPane above it, by adding it to a higher layer. However, you would need to compute where the top pane is to be located and explicitly position it there yourself.
How to Use Layered Panes tutorial
Take a look at this
http://java-sl.com/Pagination_In_JEditorPane_HF.html
Adding headers and footers in paginated content of JEditorPane. You can use the same approach calculating necessary position of your internal JEditorPane.
An alternative approache is to create a custom tag in HTMLEditorKit like described here
http://java-sl.com/custom_tag_html_kit.html
and use JEditorPane rather than button.

Java Swing: what class can be used to implement this?

What Swing class can I use to implement something like this?
Add To List http://img22.imageshack.us/img22/3260/swingwidget.jpg
EDIT: Hmm..for some reason I cannot add the image here. Well, here's the link:
Basically, I need a list table, where each column can be of different type of gui (i.e. plain text, check box, or drop-down menu).
EDIT I have re-publish the image for you ;)
You would use a JTable to implement it. Your data will be stored in a TableModel. The DefaultTableCellRenderer and DefaultTableCellEditor should do what you need, but you can also customize the rendering/behavior if necessary.
More info on renderers/editors: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender
Definitely JTable.
JTable allow you to define what render will have each column. That way you can add checkboxes, combos, textfields etc. to it.
Here's an screenshot:
alt text http://img43.imageshack.us/img43/9430/jtable.png
You can read more about it here: How to use Tables
JTable will do this for you, you're going to need to understand the MVC pattern pretty well to acheive this as you will need a custom model and renderer, but once you get the hang of it its not too hard.
David gearys book "Graphic Java Vol.2" has an excellent section on JTable, whilst this book is now fairly old I still personally think thats the best explanation of JTable I've seen.

jsf Trinidad: Change tr:table header

I have a tr:table with the rowSelection property set to "single". It draws a extra column with a radio buttons inside. But I want to change the text displayed at that column's header. I don't find any property that allow me to accomplish this. I guess I should overwrite some properties file but I haven't found anything on this topic in the Trinidad documentation.
Thanks.
As Trinidad itself doesn't seem to offer this, you can do it with javascript. It is not a clean solution, but it will work.
First, open the generated html code and find the in which you are interested. If it has an ID - document.getElementById("yourformname:tdId"). If it doesn't, try accessing it with getElementsByTagName("td") called on the table. When you have it, set its innerHTML to whatever text you want.
It is an ugly workaround, but will possibly work

Categories