JFace Tableviewer empty - display string - java

I'm developing an eclipse RCP/RAP application. I have several GUI-classes that use the JFace TableViewer (internal org.eclipse.swt.widgets.Table).
Some of my clients mentioned that it is a little confusing wether the "database-select failed" or there are just no elements.
So here's my question. Is there any way to display a "greyed out" text saying "No elements". There is something similar for the org.eclipse.swt.widgets.Text:
edtTest.setMessage("Please enter something");
Couldn't find anything like that.
Thank you in advance.

There isn't any simple support for this.
You could simulate this by adding a dummy row to the table and making your label provider implement IColorProvider so you can set the color of the row (or use one of the label providers based on StyledCellLabelProvider.
Alternatively use a separate label control and use StackLayout to make either the table of the label the visible control.

Related

Can I add to Combobox's model a different value than String?

I've created a Java Application Project in Netbeans. This project has the main class JFrame form. There is, inter alia, Combo Box. I need to add a quadratic function to this Combobox. And I really don't want to use for squared anything like this
^2 .
I've thought, that function might be represented by ,for example, .png file.(Like setting icon of buttons).
Is it possible to add a picture to the model of Combo Box?
Can be model of Combobox different than String?
Or any idea, how to add a function to the Combo Box without ^ or _ ?
I have this idea for few days, but I really don't know how to solve this.
The short answer is "yes".
The responsibility for displaying the value in the combo box comes down to the ListCellRenderer
Take a look at How to use Combo Boxes for details and Providing a Custom Renderer for specifics
Image from How to use Combo Boxes trail
Of course, how you achieve this is entirely up to you. I would encourage you to put something easily identifiable in the model and then let the renderer figure out how to render it. This is kind of important as you will need to know what the user has selected and identify it at some stage, and an Image might not be the best solution for this.

Make String look like url in TableModel

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

Create a properties frame in Java

I am trying to make a properties frame just like the one in netBeans (or Visual Studio). My problem is that I don't know exactly how to design it. First I thought I'll make it with JTable (2 columns, multiple rows) but then I realised that on the second column I will have different types of values (booleans, String, color choosers, etc.), but I think that JTable allows only 1 type of data to be placed in a column.
I would like someone to tell me "JTable allows multiple data types on the same column" and show me how to do it, or tell me a different approach to the problem.
You can perfectly tell a JTable to have a column that contains Object, this way you will be able to put whatever ou want in.
BUT.
You'll then have to implement a very good TableCellRenderer/TableCellEditor pair in order to display whatever the cell contains.
Another option would be to use a Grid or GridBag layout inside of a JScrollPane, then dynamically populate the cells of the grid with different editors depending on the data type of the property.
If you can use external libraries, the JGoodies FormLayout is really suited to create such dialogs. Just take a look at the screenshots in their demo.
There is also a rather good PDF available containing with some examples and explanations.

JList with custom cell renderer vs Jtable

My current application uses a JList and everything is well (the only customization I did was to set the italic font on some of the rows).
Now I want to "upgrade" the user interface and instead of just labels in the List, I want a checkbox and a text field to be able to update the entry.
I started changing the code and adding a custom cell renderer and a custom cell model. My current problem is that the JPanel that the cell renderer is returning is not using the whole width of the container, so several list items are actually shown on the same line.
But now, I am wondering whether I should just change the whole thing to use JTable. I still need to add / remove items in the list though...
Any suggestion which one is better ? and if going with the JList, how should I go about fixing my current problem ?
In my experience using JTable is usually easier as it allows more complex data and functionality out-of-the-box. Usually when I try to do something the JList can't do, I just switch to JTable without a second thought. What you want sounds like something that should be pretty trivial to implement in a table. I suggest you try it out with some mock data to see if you can make it look and work the way you like (especially in case you want it to look like a list).
Try calling setLayoutOrientation(JList.VERTICAL) on your JList. That will restrict JList to a single column.

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.

Categories