A hybrid version of TableViewer and TreeViewer - java

I need a Java SWT widget that can help me achieve what is shown in box 3. It should have the indentation of a tree but not display the twistie. Have tried NatTable too.. but it doesn't help.
Else, are there any hacks to achieve this?

As you are not allowed to use Nebula widgets and the customization of the native widgets below on OS layer is not recommended (it might break with each OS update) the only solution I would see is to use custom drawing. Maybe by painting over the icons.
How to do custom drawing in a table or tree is explained here: https://www.eclipse.org/articles/article.php?file=Article-CustomDrawingTableAndTreeItems/index.html

Related

What GUI component should I use?

I am working on my homework assignment and I have to achieve the following layout. Can anyone guide me as to how to achieve the right side of the view? I have already coded the left part, it's just the right side that I don't know what to use?
Calendar GUI
Should I just use paintComponent or a JTable?
JTable doesn't seems to suit your needs. You can consider using an array of JTextArea which will be added into a JScrollPane.
In this case, you can make use of the existing behaviours from these JComponents, such as setting them as editable/non-editable. Auto scrolling for JTextArea. JTextArea also allows displaying of multiple lines of records.
Should I just use paintComponent
I supposed you meant by custom painting. Using custom painting will give you alot of freedom to do your own customizations, however if the current JComponents are able to fulfill you needs, then I think you shouldn't try to reinvent the wheel, especially when you need to deal with printing text. Aligning the text properly in custom painting could cost you alot more time than learning how to use various existing JComponents.

Style TreeViewer's scrollbar

I have an editor that has both draw2d tree and Nebula's GridTreeViewer (basically a JFace TreeViewer). What I need is working, except scrollbars. In draw2d I get scrollbars provided by org.eclipse.draw2d.ScrollPane and in GridTreeViewer I get scrollbars from JFace. I am not sure why, but scrollbars look different, I would expect them to look the same since they are calling OS's native controls if I am not mistaken? Is there a reason why scrollbars look different and is there a way "downgrade" JFace's scrollbars to look like draw2d's? Perhaps there is mistake in setting up ScrollPane's scrollbars?
Here is the screenshot, this is on Ubuntu 13.04:
There is no mistake on your side. Leftmost tree has a custom-drawn scrollbar (I assume that's Draw2d tree) and rightmost tree shows native scrollbar (I guess those are the ones you call "JFace"). You can notice that most applications outside of Eclipse show scrollbars like the "JFace" ones. That is, if Ubuntu overlay scrollbars are enabled.
There is no easy fix for this. IMHO, you could try to get in Draw2d sources and try disabling their custom-drawn and replacing them with native ones (from SWT). Or you could use a custom tree instead on Nebula control...
Please note that "JFace" toolbars will look drastically different on Mac OS X or Windows, will have different size and such. And the users will expect them :)

Swing JCheckbox: Focus with customized icons

I've used
chkBox.setIcon();
chkBox.setSelectedIcon();
chkBox.setDisabledIcon();
chkBox.setDisabledSelectedIcon();
to set custom icons for my JCheckbox. But now, if the focus moves to one of the checkboxes, there is no border shown around them or anything else, which tells that the checkbox has focus.
Does anyone know, how to give some feedback when a customized checkbox has focus?
Thanks
Your problem definitely depends on Look and Feel (L&F) that you are using in your application (if you don't setup one - i guess you are using MetalLookAndFeel?).
Anyway, there might be a lot of solutions:
Check that your JCheckBox is actually focusable and focus painted. Be aware that some L&F might switch off focus painting - check checkBox.setFocusPainted() method.
If you are not satisfied with default focus painting - you might want to create your own CheckBoxUI that paints a better focus indicator. That requires some basic knowledge in UIs creation though.
If you want to paint focus indication straight on the check icon itself you can create your own Icon-based implementation that paints it together with current check state. I have posted a custom Icon example in other topic about state-dependant icon if you want to see a real example.
There might be other solutions but they depends on the L&F you are using...
You can use this ready-to use checkbox alternative:
http://codetoearn.blogspot.com/2013/01/swing-fantasy-checkbox-with-customized.html

SWT Java: How to apply transparency to GUI components / controls (e.g button, sashForm, Table etc.)

I would like to apply the same effect as shell.setAlpha(240), however was browsing the internet for couple of hours and still didn't found the solution.
Reason: I decided to improve visual appearance for application. I applied abstract image to shell background and it is only visible around of controls, which is not visually perfect.
Therefore, I want to apply light transparency to certain controls such as tables, so it will become nicer.
Thanks for help in advance.
You do not need to set the transparency to inherit background from Composite. Use Composite.setBackgroundMode() to set SWT.INHERIT_FORCE. Here is a snippet that can help

ComboBox items are overlapped

Please have a view of the attached image.
I use VLCJ to build this application. However, it is unexpected that the item in combobox is hidden by the Canvas (which is used in VLCJ player). How to solve it?
Depending on the jre version the following line may help:
comboBox.setLightWeightPopupEnabled(false);
which tells swing to use a heavyweight dropdown instead of a lightweight one.
Similar issue has been answered here, Swing: Canvas overlaps menu.
NB:
A comment on the answer there is suggesting the use of JComponent instead of a Canvas. Consider that.

Categories