Align an image in a SWT TableViewer - java

I just found out, that its somehow impossible to align an image in a swt tableviewer. Creating a TableColumn with SWT.RIGHT (for instance) has no effect on that column if its labelprovider returns an image for it.
Question: Is there any other way to align an image instead of modifiying the image file itself and put some extra pixel into it?

I believe that you're running into a limitation of the underlying platform (or something to that effect). You can have total control over what goes into the cell if you draw it yourself. There is a snippet that shows you how to do this.
Table example snippet: draw images on right side of table item
Of course, you'll also have to draw any text you want in the cell.

Related

Size of cell-component is zero in Swing JTable

I’m currently writing a custom TableCellRenderer using a JEditorPane as cell-component for a JTable. I want to make hyperlinks clickable in that component.
Therefore, I wrote a tiny hack that forwards mouse events that are fired on the Table to the specific component. The problem is, that I cannot use the viewToModel function of the JEditorPane to determine the text under the mouse cursor, because the size of my editor pane is always zero and therefore viewToModel always returns -1.
Is there any way to get the components rendered in the table’s cells to have their correct sizes set? Do you have any suggestions on doing it in another way?
Some side information: I cannot use JTextPane since I'm using the scala programming language and there is currently no implementation for it. Furthermore, I have read that it may be possible to use the native event implementation by using custom cell editors. But I could not get this working in the first place. I want that, for instance, links are highlighted by hovering over. But, as far as I can see, that is not possible with the cell editor approach, since you have to click at the cell to start editing first.

unable to resize components in java windowbuilder

I'm designing GUI using java swing with the help of windowbuilder. I found that in any layout it's not possible to resize components by using mouse drags (even though it shows points to pick and drag to resize). Specifically reducing size is what most important to do.
Resizing is allowed only in two layouts: one in Absolute Layout (which is not at all good for practical purpose, considering different screen-sizes with which GUI should be better displayed) and another is Group Layout (which is also not a good for design due to it's complex code).
Following is the sample where I have placed two JLabels and now trying to add JComboBox at the location indicated by Green box.
But when I place the JComboBox it's default size is to fill horizontally. Even if I change fill to 'None' and try to resize, I'm unable to resize it. Following is the result after addition of JComboBox:
In the Background there is JPanel with GridBagLayout with following properties:
I found that changing values in columnWidths and rowHeights properties of GridBagLayout, the size of grid columns/rows can be controlled. But I'm unable to understand Size of which columns/rows all those values represents?. (I found no direct relation between number of those values and number of columns/rows displayed on Panel)
Is there any way out to resize components? And can anybody explain what those values in columnWidths and rowHeights properties of GridBagLayout represent?
It's simple, you need to add grow in you WindowBuilder. It looks like this:
picture
Click on this with your right mouse button and click on 'grow':
picture
Only objects with 'grow' are resizable.

Jtable single cell having multiple images

I want to display multiple images in a single cell of a jtable.I know how to display a single image in a cell but how to do the same in case of multiple images?
I want to display multiple images in a single cell of a jtable.I know
how to display a single image in a cell but how to do the same in case
of multiple images?
I'm wouldn't going this way, because XxxRanderer is called from every mouse and Key events over visible JTables Rectangle in the JViewport,
prepare this image before, put together all images to one and put only one Icon/ImageIcon to XxxTableModel
DefaultCellRenderer returns JLabel by default, add proper LayoutManager to JLabel and laid there images, save images to local variable to avoiding any FileIO on runtime
There are at least two ways I can think of doing this...
You could merge all the images into a single image and allow the default TableCellRenderer to render the result as normal
Or...
You need to supply your own TableCellRenderer capable of taking the multiple images and displaying them.
Probably the simplest would be to use a JPanel as a base and add a JLabel per image. This would be a rather expensive process (assuming your have a dynamic number of images per cell), as you would need to remove all the labels from the panel and add the new ones for EACH cell.
See Using Custom Renderers for more details.

Drag and Drop in Java - Painting more than just a border

I have a JTable and a JList and I have my code set up so that I can drag from the JTable to the JList using built in Swing methods.
When I drag from the JTable to the JList, the "image" that is dragged is simply a border of the thing I am dragging. Specifically, in the case of the source being a JTable, the image is just a border of the row I selected to drag.
How can I override what this "image" is? How can I get it so that the user can drag text, not just a border (rectangle)?
You could check out
http://rabbit-hole.blogspot.com.au/2006/05/my-drag-image-is-better-than-yours.html
http://rabbit-hole.blogspot.com.au/2006/08/drop-target-navigation-or-you-drag.html
http://rabbit-hole.blogspot.com.au/2006/04/smooth-jlist-drop-target-animation.html
http://rabbit-hole.blogspot.com.au/2006/07/drag-images-for-everyoneand-we-do-mean.html
Now some may not be quite what you after, but he's done so much with drag n drop, it'd be waste note to check out as much as you can
You may be able to take advantage of Drop Location Rendering to achieve the desired effect. If you are already doing so, please edit your question to include an sscce that exhibits any problems you encounter. This example may be helpful.

how to make java run time sizable image box

I'm making a Unicode translator in Java. I did all hard parts, but now I want to add a resizable, relocatable image to the textpane. The user must be able to resize image with its corners and drag & drop the image within the textpane where he likes. (like Microsoft Word or Photoshop)
Something like this:
I tried the Styled Document properties. But I couldn't find way except inserting only an ImageIcon.
May be a better choice would be not to use textPane.
If you have an custom editable label, that can be edited by double clicking on it to show a text box to edit the contents, and change the text of the label when enter key is pressed.
Also give a shot of JDesktoppane, JLayeredPane, and check what components can be added to it.
try this
http://mgeisler.net/downloads/browser/src/ImageBox.java.html
try loading the image inside a JLabel component in JFC Swing.
Otherwise try some other non editable components in the same technology with resizable property.
try this http://sourceforge.net/projects/ird/
the iRD is a component for Resize and move(drag&drop) compoennts on runtime in java.

Categories