I want to display an image in a label. But using image icon property I cannot set the size of the image. So I am using HTML coding in the text property of JLabel to display image.
The image is not displaying so there must be some error. The alt text is being displayed. I tried the same coding in notepad and it worked. Please mention if there is any other way to display an image of a fixed size in label.
<html>
<body>
<img src="file://C:/Users/Lenovo/Desktop/Wallpapers/New folder/1mb.jpg" alt="Smiley face" height="142" width="142">
</body>
</html>
Is there a simple way to resize the image icon then please answer that also. I am making a project for my school so the codings should not be oh high level.
Thank you.
Related
I have one requirement in which I need to print a web page(actually a jsp page created using struts 1.3 ) using browser's print option in such a way that buttons which are there on that webpage should look little darker in print or in pdf(when we use save as pdf).
I had tried below code inside head tag:
<style>
#media print {
.light {color: #000 !important; }
}
</style>
I put the buttons inside a div and tried to apply .light class on that dive so that only during print or saving it as pdf buttons should be visible darker.
buttons code is as below (struts bean tag is used here):
<div class="light">
<bean:message key="button.internet.request.update" />
</div>
<% } %>
</html:submit>
<% } %>
so I added line no. 1 and 3 just for putting the button code inside a div and applied that .light class. But it didn't work.
Help me appling the css code in bean tag so that button gets printed darker on print page or visible darker in pdf.
Images for proper button and disturbed button I have attached. Proper here means before applying my code and disturbed one is for after applying my code which didn't work.
I created a buttton in html and linked it to another html file, when i open the file with the button in a browser (tried IE and FFox) the button shows and works properly, however when i JEditorPane.setPage(the html file with the button) the only thing that shows is the name of the button with no actual clickable area or anything! Any ideas on how i can get the button to appear inside the pane?
Here's a pic of the button in the java frame(button is circled in red)
http://tinypic.com/r/fopswo/6
Here's a pic of the button in a browser(it's a button)
http://tinypic.com/r/2zjj71z/6
The code for the button
<font size = 12 face = "verdana" ><u> Creating An Account </u></font>
<span style="padding-left:360px"> </span>
<button onclick="window.location.href ='file:///F:/java 12/Isp/help file try/doc 2/test.html'">Back</button>
Thanks in Advance
Swing's HTML support is patchy - I think you have fallen in one of its holes. More info here:
Which HTML tags are supported in Swing components?
Is it possible to run JavaApplet when you press a button , or when you click on the image on the webpage?
Maybe you guys can share any example, related html/jscript/jquery?
What is wrong with my code at this point?
<html>
<script>
function openApplet(){
var attributes = {codebase:'.',
code:'d.Applet',
archive:'Applet.jar',
WIDTH=500, HEIGHT=300} ;
}
</script>
<body>
<applet id="myapplet"
CODEBASE="."
ARCHIVE="Applet.jar"
CODE="d.Applet"
WIDTH=500 HEIGHT=300
style="visibility:hidden;"
>
</applet>
<input value="Applet_on_Click" onclick="openApplet()" type="button">
</body>
</html>
I'm just looking for very simple solution. Click on the image , applet shows up, click on the different image , another applet will show up. Or maybe these things can happen when we press a button too?
Update
Thank you slowpoison for the information!
But I'm missing something.
There is my original code now:
http://www.text-upload.com/read.php?id=360320&c=7544773
This is working just with pure html. But there is no action when you click on the button.
If I disable this row "style="visibility:hidden" , applet will show up without a click.
I wan't to show applet just after the button click. :(
You should add the applet tag to the document in the onclick handler.
var applet = document.createElement("applet");
// fill in various attributes for applet
// ...
// "install" the applet
document.getElementById("appletContainer").appendChild(applet);
I'd like to use a WebView for displaying images potentially big (in order to seize it memory management).
For the test i'm loading this code in the WebView
<head></head>
<body>
<img alt="test" src="file:///android_asset/cute-cat-sleeping.jpg">
</body>
The problem is that if I load it in a web "as is". The WebView only allow to zoom out until the first dimension of the image is fit in screen. In this example the image height is totally shown into the WebView and then no more zoom allowed:
As you can see this mode doesn't allow a correct display of the global image despite that when the image is zoomed the behaviour in the right and bottom corners are correct as you can see here
So I tried the (WebView).getSettings().setUseWideViewPort(true) and the result is that I can zoom out more than the image's width
and the zoomed behaviour is not correct in the bottom-right borders:
Summarizing: I'd like the max zoom out possible to be imageWidth=webview width and zoom behaviour like in the second image:
Complete and/or usefull answers will be bountied
EDIT: Bounty opened for Vinayak.B
Using Viewport Metadata may help you to do this
The viewport is the area in which your web page is drawn. Although the viewport's visible area matches the size of the screen, the viewport has its own dimensions that determine the number of pixels available to a web page
Also try below
WebSettings settings = webView.getSettings();
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
Load Html file in Webview and put your image in asset folder and read that image file using Html.
<htm>
<table>
<tr>
<td>
<img src="cat.gif" width="100%" alt="Hello">
</td>
</tr>
</table>
</html>
Now Load that Html file in Webview
webview.loadUrl("file:///android_asset/abc.html");
Or another way
if you use LinearLayout, can take a background parameter that can be a colour or a resource.
So in main.xml file contains webview. you simply added a
android:background="#+drawable/backgroundmain"
and use
web.setBackgroundColor(0);
To make the webview transparent to see the background image behind.
here is the solution set the img tag width to 100% in HTML code and then load it in your webview using loadDataWithBaseURL(null, htnlString, "text/html", "UTF-8", null); method
try this code
String htnlString = "<!DOCTYPE html><html><body style = \"text-align:center\"><img src=\"http://shiaislamicbooks.com/books_snaps/UR335/1.jpg\" alt=\"pageNo\" width=\"100%\"></body></html>";
yourWebView.loadDataWithBaseURL(null, htnlString, "text/html", "UTF-8", null);
Edit your Webview:
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
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.