Displaying and interacting with HTML within Java - java

I have a problem which I am currently trying to wrap my head around, and any advice or nods in a good direction would be greatly appreciated.
I want to display a Google Map within my Java Swing project, (the map will be a URL specified within an HTML document I think).
I also want to be able to communicate and interact with the map using JavaScript, injected via buttons in java swing, etc. So for example, I could have java buttons 'Satellite', 'Hybrid', and 'Earth' next to the map, and clicking them would perform the corresponding javascript action on the map. JavaScript methods would probably already be created within the HTML file (such as 'switchToSatelliteMap'), it would just be a matter of calling them within Java.
Thanks in advance for any help whatsoever,
tre.

I don't know whether this answers your question at all, but I think you will find these links helpful:
http://today.java.net/article/2007/10/24/building-maps-your-swing-application-jxmapviewer
http://swinglabs.org/downloads.jsp
GoogleEarth inside Java Swing
Is there a Swing component for Google Maps?
http://code.google.com/p/gameplan/source/browse/trunk/src/org/crazydays/gameplan/map/swing/JMapFrame.java?spec=svn62&r=62
I am more of a SWT fan, so I would have used a browser control as it allows me to execute javascript on the browser component. But again its a design choice.
Hope this will help.

I am not entirely clear on the scope of your issue, but you may find it helpful to attach MouseListener interfaces to your swing buttons
http://download.oracle.com/javase/7/docs/api/java/awt/event/MouseListener.html
http://download.oracle.com/javase/tutorial/uiswing/events/mouselistener.html
Implementing the mouseClicked method to run the required java script.
Additionally you could use a MouseAdapter if all you need is the mouseClicked functionality.

Related

interactively show/hide components in java

I would like to create a java gui which has a main component and a side component which can be hidden by the user. can anybody help me where to look at (classes, methods) or even link to simple examples?
Sounds like a classic example for a split pane...

Create java GUI programmatically rather than using java look and feel

the java programming offer you to create Java GUI (J2SE) with two options. As we known, there are programmatically(Coding from scratch) or using Java look and feel(Drag & Drop). As my experience, its very easy to create Java GUI using java look and feel rather than programmatically. So, i'm frequently using java look and feel. ;)
Now, i'm know its wrong, because its limit us to create dynamic application. So i wanted start to create java application (J2SE) programmatically. But my question is very simple, how to create this frame programmatically as below :
As we know, its very simple using Java Look & feel (Just drag and drop). How to create space between jLabel1 and JtextField1 as we desired? And how to create leading space(Space below and after) between jTextField1 and jButton1 as we desired?
I know this is very stupid question for java expert, but perhaps this question can help other people(particularly java beginner) to start learning Java Programming and not doing as what i'm doing now. :)
Thanks for your advice, sorry for my bad English and possible duplicate question. :)
In Java, you typically create a hierarchy of JPanels (Swing), each having a suitable LayoutManager (GridLayout, PanelLayout, BoxLayout, GridBagLayout, etc...). See the link below for details;
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
Using layout managers is the best dynamic approach for creating scalable and dynamic UIs, but there are lot's of drag-n-drop utility applications that set layout manager to null and thereby allow for pixel-based exact positioning of your different components. In your case, a JLabel, a JButton, and a JTextField.
Hence, to create the exact UI you shown, go for null-layout and place your component instances on upper-left-corner (x,y) positions relative to your frame's origo (again, upper-left corner).
If you use the Drag-and-Drop interface, it should generate some code for you. Examine this code and use it yourself, making changes as you like. The DnD interface is nothing but a layer on top of the code.

Calling a Java method using javascript from within a JPanel

I have a Java application which displays results on a JPanel. The results are displayed using HTML by using a JLabel.
Now I want to let the user interact with the local application by allowing local methods to be called when the user clicks on a link in that HTML document.
Is this possible?
To answer you question, then, it is possible, however you cannot use a JLabel, you need to insert a JavaFX component, and then you can set your class as a window variable on the DOM, and thus your methods can be called from JavaScript.
Have a look at this answer on this question. It looks like they are doing exactly what you want.

Java, Swing, Netbeans: how to create an interface similar to the iPhone's SMS screen?

I'm looking to create an interface similar to that of the iPhone's SMS screen. More specifically I'm looking to replicate the "bubbles" coming from each side of the page which contain the messages, as shown here http://www.bidslammer.com/images/iphone_shot1.png .
I do also want to recreate the date and time above the bubbles like you can see in that image. I need to be able to do this by code because its use will be to display the messages that it receives over my socket connection, and show the messages I send over the socket.
I'm really new to Java, and even newer to Swing, so I'm looking for some pointers on how I should go about this.
Can anyone offer my any suggestions about how I would go about doing this? I'm not looking for someone to do the work for me, just a few pointers, perhaps some things I should learn how to use/do and perhaps a helpful tutorial or two.
Google for "swing tutorial" gives a lot of tutorial links, so just pick one. When I was learning Swing I used original Java Swing tutorial.
As for some pointers, I think good idea is to use images to represent the bubbles - that will be the easiest. Inherit some basic component like JLabel or JPanel and override a drawing method - do a custom drawing. First draw the bubble image and then the text over it. This may help with image drawing.
Generally with custom component drawing you use Graphics class, which provides a lot of useful drawing methods.
The sticky notes demo might get you started in the right direction.
Even though that demo is a NetBeans platform module, the sticky note itself is a pure Swing component and should be usable without the platform.

What is the best way to make clickable text in java?

This is for an application so I don't want a hyperlink. I first tried using a Jbutton without all of border/background stuff and then hooking up an actionListener to it but I couldn't get it to the point where I thought it looked nice. I also tried using a JLabel and hooking up a mouse listener to that but I also couldn't get it to look right.
Basically I would like a way using swing to make a button exactly like a url link in an application. What is the standard way of doing this?
but I couldn't get it to the point where I thought it looked nice
You might want to go into greater detail on just what "looked nice" means. I can see you solving this by either a JButton or a JLabel, but the key is perhaps not to look for another solution but to play with the settings of the button or the label til they look nice. If you can't find a nice solution, then post your code (an SSCCE would work best of all) and perhaps we can help you.
that isn't answer to your question but are you tried to add ButtonModel to your JButton example here
It is a rather heavy hammer to use, but SwingX has a JXHyperLink control that is probably exactly what you want. The source is at http://java.net/projects/swingx/sources/svn/content/trunk/swingx-core/src/main/java/org/jdesktop/swingx/JXHyperlink.java?rev=4027 and you can see an article about it at http://www.javalobby.org/java/forums/t18617.html.
It is old, but SwingX continues to do good things.
It's you're trying to make a desktop application which looks like HTML inside a browser, you might try using some of the richer Swing text components in a read-only mode. You could use a mouse-listener to map X/Y clicks to a particular character of text, and then cause an action to occur on that basis.

Categories