interactively show/hide components in java - 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...

Related

Futuristic GUI in Java?

First of all sorry for my english, it's not my mother tongue.
I want to made a program in java, i was thinking that it will look great with a futuristic graphical user interface. When i say "futuristic", i mean something like this:
I know it's the image of an Android application but i'd like to do something like this in a java program.
Usually when i have to do GUIs in java i use Swing components, but now i need to personalize everything, and i'd also like that when i click "Send" for example the circle becomes bigger and other things appears inside it.
So i need to have a complitely personalized and animated GUI. Which is the best way to do it? Swing, Awt, JavaFx or what else?
Thank you in advance.
Consider to use JavaFX. It supports styling via CSS, has APIs for effects, animations etc. and can work with the graphic card.
Swing is currently in maintenance mode and JavaFX is the new proposed (by Oracle) standard Java GUI toolkit for Java.
You could extend JComponent for every different component you want and then override the paint(Graphics g) method. Then you just draw on g object like on any other graphics object.

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.

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.

Creating mixed components in swing + java

Is there any way to create a custom component in swing. By custom I mean say right now I am able to create a circle and do actions like dragging it etc.
But now I also want that along with the circle a text label with its number is also present. Can we combine them into a new type of component where say we can do actions on it collectively?
If yes please give me pointers on how to do so.
Yes, just extend JComponent and handle painting and interaction however you want. If there is a component that already does most of what you want you could extend that class and tweak it slightly.
I would suggest reading some of the tutorials about how JComponent works:
http://download.oracle.com/javase/tutorial/uiswing/components/jcomponent.html
Here is a similar question but I am sure you can find more specific ones that have been asked once you get deeper into it.
How to create a custom Swing Component
The Swing tutorial as a whole if very useful to understand how other components work etc.
http://download.oracle.com/javase/tutorial/uiswing/components/index.html
You can create your own Swing component extending JComponent. Several question here on Stack on the topic like this one.
Personally, I advise you to get this book: Java Swing as it contains an excellent guide on how to create Swing components.

Displaying and interacting with HTML within 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.

Categories