Is there any material/tutorials available that can shed some light on creating drap and drop widgets with Java 2D? I am not talking about drag and drop data transfer like here. What I want to do is have a visual pane in my application, where users can create widgets, connect them to each other etc. Something like a creating a graph, but with widgets that have properties.
Thanks.
This is generally works like this:
When a user presses the mouse button your application goes to a "drag" mode
When repaint() method is called while you're in drag mode you move your widget position to the coordinates of the cursor
When mouse button is released you fixate the ultimate position of the windget.
The simple illustration for this might be a program I was writing in my youth - interactive chess board. Here is relevant class that includes pieces dragging capabilities http://jinyan.svn.sourceforge.net/viewvc/jinyan/trunk/jinyan/client/src/net/sfficslecview/lvboard/EditableChessBoard.java?revision=77&view=markup
I have found the perfect solution. I can make use of the Netbeans Visual Library by extracting jar from the Netbeans Platform.
Related
I am attempting to create a a java GUI for use on Zedboard with the 7" touchscreen display. The GUI I am creating is supposed to mimic exactly (though scaled down) a physical console with many interactive buttons.
My question is what would be the best method in making the buttons interactive, my first thought was to cut out the buttons of the console and have each one a separate image that can be set as interactive, but I feel there may be another simpler method.
Thanks
LDY
For the console mimicking, you could take an image of the entire console and then listen to touch event at specific points in the image which corresponds to a button. Based on where the touch event occurs, you could do different actions.
For this you need to get the coordinates of the touch event and check if it corresponds to any of the buttons on the console.
I want to create interactive drag and drop. What I mean is that i have 10 slots and 5 buttons, I want to make that user can drag and drop a button on the slot he wants to. I made it with ComboBox and it works fine but I want to make it more interactive. Is it possible in an easy way or I need a hard code? If so any good help on coding would be appreciated.
//Edit. I made it with ComboBox using setLocation(); with saved every slot position
//Edit again with photo:
You can see several example of Drag and drop in Java here and decide which kind of drag and drop you would like to do:
http://docs.oracle.com/javase/tutorial/uiswing/examples/dnd/
I am making an image processing application in Java. I have written all the code for the processing part, I just need to make a user interface for the same. The user interface looks like this :
It has a browse button to select an image, Once an image is selected, it is to be displayed. The user can now select multiple rectangular regions on this image using mouse (the user clicks at a point in the image and drags mouse to select the region of interest). All selected regions appear shaded. The selected regions also appear in a list, so the regions can be un-selected by deleting the corresponding entry from the list. Finally the user can click on a "process" button to perform the image processing.
I want to know what java gui technologies do i need to create such an interface, and any good resources from where i can read the same. I need resources, for example, about how to manage the layout, display images, mouse events on images etc.
Read the Java trail about Creating a GUI With JFC/Swing.
You will find better answers there than here.
Also, you can use Netbeans; it has a great GUI editor. Or you can check out Google WindowBuilder Pro and install it in your eclipse.
Using Java is there anyway to display a custom form/image that behaves similar to TrayIcon.displayMessage() function in that it displays just above the system tray for a while then disappears?
I am also looking for a way to display multiple notifications at the same time by having them display above each other.
If not, how do I find the pixel location for the lower left corner just above the system tray?
I don't think there's a shortcut for drawing frames that act just like the standard TrayIcons (with the x button in the corner) that support stacking akin to the Mac Growl notifications.
you will probably have to implement it yourself.
I've found that stacking messages like that is a complete waste of time as the user will not pay attention to them - the better location for these is in the status area of the application in a simple popup menu.
You can use java.awt.GraphicsEnvironment. getLocalGraphicsEnvironment() to get information about the desktop, which contains 'getMaximumWindowBounds()' which takes care of things like the taskbar position.
You can use a subclass of a javax.swing.JWindow to create a window without a border which can be positioned on the desktop relative to the bottom right corner. This will not always work as the default tray icon, as the location of the icon generator can be somewhere else other than that.
You can add a button that acts like the 'x' button of a standard desktop window - but it's going to be platform dependent.
I use square windows that stack up from the top right corner if I'm using LTR, and it seems to work well.
Go check out Java GNOME. It has Java bindings for GTK, including a status icon for the tray, and notification events.
I try to build a gui (Swing) for a simple java application. The application should have a start window like a menu. From there I would like to navigate to several other windows.
My question is what is the best-practice to achieve such a navigation? Should I build several JFrames and switch the visibility of them on/off when navigating OR should I better have one JFrame and add/remove JPanels in this single frame to navigate between the windows?
Thanks.
I recommend
Do not do a MDI application with sub-frames like those found in the old Windows days. They suck as they make the matter confusing.
Do design a tabbed interface. The welcome page/menu will be displayed on a first tab that is always created on the start.
All cool kids do that nowadays:
Visual Studio
Eclipse
Firefox
If each of your windows correspond to different task (possibly nested), you could present your application as a SDI, with on the left a task panel like:
Each of the task would display one JFrame with the associated window.
Other solution: a table of content like this picture on the left side
(note: it actually also displays a task panel in this example on the bottom right)
Multiple JFrames sounds like a better idea to me. Much more OO.
You must find a balance between these goals:
Not too many things in one "window"
The user must quickly be able to find the correct window to do the next step of work
All relevant information must be visible at any time
Eclipse solves this by creating many small editors where each editor shows some specific information and allows to modify it. Editors are then arranged within one OS window in tabs and "views". A view is always completely visible and they can be arranged. Think of a view as a way to cut an existing editor in half (horizontal or vertical) and then being able to replace one of the halves with another editor. Between each half, you have a splitter so you can adjust the sizes.
Arrangements of views are then saved in "perspectives".
This allows every user to create a perspective which contains all the necessary editors at the same time, arrange them as they need it and work effectively.