How do I get a file's icon in Java? - java

I'm making a basic file browser and wish to display the icon of each file. Is there any way to get this?

Icon icon = FileSystemView.getFileSystemView().getSystemIcon( File );

Related

How to open PDF file in new window in browser?

I'm trying to open a PDF file by requesting it from Rest endpoint. But in this case, the file is getting downloaded. I tried opening it in another window. There also it just shows new window and downloads it there.
I used Chrome. So in Chrome by default it downloads the file while in Firefox it shows the dialog box whether to open it or save it. I don't want that dialog box. But want to display the file in new window with all the features like download, print, etc which a normal pdf viewer will show.
Is there some way through which I can avoid downloading of the file by default and just display that file in another window? Content-Disposition is attachment; filename="abc.pdf" when I see the properties of the URL. Also, its content-type is application/pdf;charset=utf-8.
<a target="_blank" data-content-type="application/pdf" onclick="open(this.href, this.target, 'fullscreen=yes'); return false;" data-type="downloadTenPointDocument" href="<c:out value="${resultItem.offer.programInfoUrl}"/>">View 10-point</a>
I changed the properties of pdf file from attachment to inline and set it in response:
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "inline; filename=" + fileName + ".pdf");
I am requesting the pdf file from server and then reading it and setting it in response, changing the properties of it in response, so that its default behavior of getting downloaded is overwritten.
Thank you everyone. The answer to change the property of pdf file was right.
You won't be able to do it directly from REST endpoint.
Use target="_blank" in anchor element on your page.
go
You should try to erase attachment; property from content disposition header.
i did like that and it worked: (it wont start to download, and it will open in a new tab (target _blank) if same tab, thenit is (target _self)
show pdf in a new tab

eclipse plugin: add image to browser

I have created an Eclipse plugin which displays a browser with a URL as follows:
browser.setBounds(0, 0, 100, 100);
browser.setUrl("https://www.stackoverflow.com/");
Also I am able to get the animated image from the bundle as follows:
Image image = ImageDescriptor.createFromURL(FileLocator.find(bundle, new Path("icons/sample.gif"), null)).createImage();
How could I add the Image to the browser on run time execution?
Since you're setting the Browser widget to display a URL, the widget will display the contents of that URL.
If you want to display your own content, you'll have to use the setText() method.
Perhaps you can create html that includes the URL you want in an IFRAME and compose the rest of the html with your own content?
As for the image, I'm sure there are ways to include the image in the constructed HTML ... or you can base64 encode the data and include it in the constructed HTML. See Can I embed a .png image into an html page?

disable and enable buttons on Java

I have a form with many data. In this form the user can click on "view report" button which will load a pdf file from the folder, if the report exists.
I'm trying to find a way that the button will appear flat and won't be able to click it if there is no report to load and the button will appear regular and will be abled to click on if the report exists and can be load.
basically i'm trying to avoid clicking on the button in any case and if the report exists it will be loaded and if not it will gives an error msg.
The goal is that just by looking at the button the user will know if there is a report or if there isn't.
How can I make it possible assuming I have 2 images ready (flat and regular).
if (fileExists)
JButton.setEnabled(true):
else
JButton.setEnabled(false);
Have you thought of just using:
myButton.setEnabled(false);
and later when it's ok to use the button:
myButton.setEnabled(true);

display html in popup

What we do is we define a webview and make the html files being displayed in that. Is it possible to display an html file in android's default pop up on the same screen? I have stored the html file in assets/www folder.
Please let me know regarding this
It is possible to display a WebView or any other UI in a default Android Dialog. But, it is better and easier for you to make your own custom Dialog class and display the WebView in that. You can also make it an Activity and use the Dialog theme to make the Activity look and behave like a Dialog.
You are correct to put your .html file in the "assets" folder. That is what I do.
Load the WebView like this:
private final static String url = "file:///android_asset/file.html";
webview.loadUrl(baseUrl);

JEditorPane embedded images cannot be displayed

Good evening,
I've been trying to display html code in a JEditorPane with embedded images. The code for the image that I receive is the following:
<img title="1909-yamaha-nemesis2.jpg" alt="1909-yamaha-nemesis2.jpg" src="cid:ii_12d7652d11e8d9a6">
As you can imagine, I cannot display the image, any idea? I suspect it should be the CID codification.
Thank you in advance,
http://java-sl.com/tip_local_images.html
You can use the same approach and place your image in the local cache.

Categories