Make HorizontalSplitPanel adjust its width to content- in Vaadin 7 - java

I am using Vaadin 7 rc1.
I would like to create a HorizontalSplitPanel that adjusts its width if the left side is wider then the given width.
The default behaviour is that a scrollbar appears on at the bottom of the screen if the content is wider then the given size. However I would like to have the left side widened.
I am new to Vaadin and the book does not go into details like this.
How is this possible in Vaadin 7?
Any help is appreciated!
Thanks!

Try to call method setSizeFull() on the HorizontalSplitPanel.
Then open the application in e.g. Chrome and Inspect the split panel element. See what has been changed and try to play with width/height values in the inspector. That might give you a clue what is wrong. Maybe you need to call setSizeFull() also on components that are contained in split panel?

The is a function in HorizontalSplitPanel that do exactly what you looking for :
panel.setSplitPosition(float f, Unit unit);
You can use either
Unit.PERCENTAGE
or
Unit.PX
... there is a lot of possibilities.

I have managed to solve the situation with other layout structure.

Related

How to change JavaFX slider thumb color without CSS

I'm using ScalaFX, which is currently proving itself to be thoroughly useless and bugging out anytime I try to use css. Is there any way to change the fill color of a Slider without using css, or at least without separate css files?
I've managed to change the track color with slider.setStyle("-fx-control-inner-background: #f08080;"), but can't get the thumb working.
You could use the -fx-base property, which sets the component colors palette according to the value you specify.
Example:
slider.setStyle("-fx-base: #f08080;");
Result:
However why don't you consider using a CSS file? It simplifies everything and allows you to make a lot more customizations. Take a look at the Slider JavaFX CSS reference, I think you will find what you're looking for.

Vaadin 14 components not show up / not visible

I'm developing new module in our application using vaadin14 components (eg https://vaadin.com/components/vaadin-date-picker). Everything worked pretty well, but after adding few components (text fields, grids, buttons, labels, notifications etc..) vaadin decided to not listen to me anymore... ;(
Everything started when I've tried to add some addon - slider (because for some reason it was removed from vaadin14). Even I tried a bounch of different addons none of them seem to work, it always lead to not displaying component(it was visible in html code when I was checking html elements on website, but size of that elements always was 0x0 - even setting its size in style didn't seem to work, because - yes it took some place on gui, but was invisible).
I thought that it might be some issue with my vaadin version or some deprecated addons and I've returned to work with default vaadin components. But this time it not seem to work as well. Currently the same issue is with IntegerField, NumberField, DatePicker, ProgressBar and I think that there is much more. There are no errors in console, no errors from server side, html elements are visible in generated html but its size is always 0x0 or not visible(eg vaadin-data-picker 0x0 data-picer 0x0).
Eg.:
html egxample
Like you can see there are no styles visible or whatsoever..
Code that should generete them looks like that(it is taken straight from vaadin example):
IntegerField integerField = new IntegerField("Age");
integerField.setSizeFull();
integerField.setVisible(true);
add(integerField);
NumberField numberField = new NumberField("Years of expertise");
numberField.setSizeFull();
numberField.setVisible(true);
add(numberField);
DatePicker labelDatePicker = new DatePicker();
labelDatePicker.setLabel("Label");
DatePicker placeholderDatePicker = new DatePicker();
placeholderDatePicker.setPlaceholder("Placeholder");
I've tried everything - using .setSizeFull(), setVisible(true), rebuilding project with mvn clean install (production and dev mode), deleting node_modules, targer, webpack.generated.js, package-lock.json(both on main directory and module directory) to let vaadin recreate them. But nothing seem to help. On different machine we was able to display NumberField after few rebuilts, but after few more it disapears again...
Thank you in advance!
EDIT:
Check the difference between working and not woring element:
Working element
Not working elements
Like you can see above in working element is bunch of stuff like shadow-root, styles, div etc. I assume that other elements also should consist such.
Try with setSizeUndefined() or use fixed sizes instead, or make absolutely sure all the parent layers also have full size.
When you use setSizeFull() you are telling the component to spread out to use all the available space, but if there is any container parent in there that has undefined size, that one will only use as much space as the contents demand -- which is nothing, if the contents are all set to full size. All the available space of nothing is nothing.

Vaadin 10 Grid add custom image icon

I am using a Vaadin 10 (Flow) Grid to stream data to new rows, and I am trying to add a custom image icon to my TemplateRenderer.
I have a TemplateRenderer setup like this:
TemplateRenderer<TradeUni> sizee = TemplateRenderer.<TradeUni>
of("<div class$=\"[[item.class]]\">[[item.size]]</div>")
.withProperty("class", cssClassProvider)
.withProperty("size", TradeUni::getSize);
Which displays my numbers correctly in the grid cell like this:
I would like to have my image rendered inside the same cell, to the left of the numbers.
This was my (very crude) attempt to import it using html:
TemplateRenderer<TradeUni> sizee = TemplateRenderer.<TradeUni>
of("<div class$=\"[[item.class]]\"><img src=\"i.imgur.com/3LQBglR.png\">[[item.size]]</div>")
.withProperty("class", cssClassProvider)
.withProperty("size", TradeUni::getSize);
Which give's me this:
I think that I might have to wrap the image and numbers into a HorizontalLayout with the image being a separate component - I think I could handle that, but I am unsure of how to do the actual rendering of the image. I can probably accomplish it simply with the internal Vaadin Icons set, but I need to use my own little images.. all icons that I am going to use will be at or less than 25 x 25px.
Thank you so much in advance!
I think you're on the right track, but there's one small detail that causes you trouble. The URL i.imgur.com/3LQBglR.png doesn't define a protocol, which means that the entire string will be treated as a path relative to the location of the hosting page. It will thus try to find a file in a directory named i.imgur.com on your own server.
To fix this, you need to also include the protocol in the image URL, i.e. https://i.imgur.com/3LQBglR.png.
I can also offer a small suggestion for how to make the code easier to read. HTML also supports using ' for enclosing attribute values. This is more convenient to use from Java string since you don't need to use \ to escape ' characters. Your template string could thus be "<div class$='[[item.class]]'><img src='https://i.imgur.com/3LQBglR.png'>[[item.size]]</div>".

JList: Horizontal_WRAP fitted?

Hey,.. i wanna show pictures with names onit in a jList, i know it get's also in a JPanel but i'm now using a jList, doesn't matter..
My question is why does the jlist don't fit the images only in 2 horizontal 'cells' and then go one row down?
sry my english is bad and i don't know how to describe it better, but look on the picture, why does the jlist dont set the e.g. 3rd picture right next to the 2nd?
JList.HORIZONTAL_WRAP works correctly in the ListDialog JWS demo, as described in Initializing a List. I suspect a layout problem, but you might compare your code to the examples found there.
If you use HORIZONTAL_WRAP you can adjust the number of columns with setVisibleRowCount. If you want them automatically fitted to the width of the list, use 0 or something negative.

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.

Categories