JEditPane inside another JEditPane in swings(java) - 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.

Related

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>".

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

Make HorizontalSplitPanel adjust its width to content- in Vaadin 7

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.

How to make an image Viewer in swing?

I am trying to make an image Viewer like the one shown in the figure below:-
Before i can start i have following questions in mind :-
How would i check for the number of images in the target folder so that i can iterate and include all the images in my app.
Secondly,i am thiking to scale the images down to 75x75 .But what i can't think is that how will i slide the images as scrollbar is moved
To be specific,what is the appropriate container for those 75x75 images queue and how that queue is shifted to left or right?(I already know how to get current scrollbar value and add event listeners on it to respond)
To check the number of images in the target folder you can use the File class.
As for the container you might need to create the animation your self. There is no a container ready for doing so.
This site ( and book ) has some ideas about it. I don't know how out-dated it might be though
http://filthyrichclients.org/
Unless I am misunderstanding, making a scrolling list of images is quite simple.
First, create a JList with a datamodel that allows images.
A great example is shown here:
Java drag and drop images in a list
Second, add the JList to a JScrollPane.
The scaling aspect can be easily performed using Scalr:
http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/

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.

Categories