swing

JToggleButton not painting.

Ok, So I make a JToggleButton: JToggleButton button = new JToggleButton(new ImageIcon(features[i].getImage())) { private static final long serialVersionUID = 1L; @Override public void paint(Graphics g) { super.paint(g); if (isSelected()) { g.setColor(Color.RED); g.drawRect(0, 0, getS...

JTree of objects?

Hello, How I can implement dynamic Jtree, which shows created instances of clases? For example, I can create new Book(name) in my app. In every book can be chapters = ArrayList of Chapter. And now How I can do a jtree from it? ...

Problem with custom component on swing

I'm not used to GUI development, but now I need it a little bit, and I want to avoid reading all documentation just because of this problem. I'm having trouble displaying a custom component like the one I posted below. If I add it to a JFrame it works fine, but I cant add more then one, and if I add it to a JPanel it wont be displayed a...

JPanel's child components paint/layout problem

I'm having a problem that when my frame is shown (after a login dialog) the buttons are not on correct position, then in some miliseconds they go to the right position (the center of the panel with border layout). -- update In my machine, this SSCCE shows the layout problem in 2 of 10 times I run it: import java.awt.BorderLayout; impo...

how to obtain mouse click coordinates outside my window in Java

hi, I need to implement a class, using Swing, which can obtain the mouse coordinates when the user clicks anywhere on the screen. if I wanted to obtain the mouse coordinates inside my own window, I'd use a MouseListener, but I want it to work even when the user clicks outside my program. I want my class to behave just like KColorChoose...

Java Swing KeyStrokes: how to make CTRL-modifier work

In the following program, why does hitting the 'a' key print "hello, world" while hitting 'CTRL-a' doesn't? import java.awt.event.*; import javax.swing.*; public class KeyStrokeTest { public static void main(String[] args) { JPanel panel = new JPanel(); /* add a new action named "foo" to the panel's action map */ ...

make a JLabel wrap it's text by setting a max width

I have a JLabel which has a lot of text on it. Is there a way to make the JLabel have a max width so that it will wrap the text to make it not exceed this width? Thanks ...

How can I cancel Drag and Drop operation in Java/Swing programmatically?

I am just wondering if it's possible to I cancel "Drag and Drop" operation in Java/Swing programmatically? So the effect would be similar to if the user pressed the "ESC" key? I was expecting DragSourceDragEvent or DragSourceContext to have a cancelDrag() method, similar to DropTargetDragEvent which has acceptDrag() and rejectDrag() met...

Java Swing - Background of a JPanel

I want to design a JPanel which should have the color coding as shown in the following diagram: How can I code the colors of a JPanel. What I think is that add 5 JPanels (for 5 blocks shown above) on a main JPanel. Set the background of each JPanel to light Gray. But then how can I achieve the dark color lines as shown in the diagram...

How to switch frame to another frame in java programming?

Let's say there is a button and if you will click that, a new frame will appear and so on... ...

Java Swing - Should JTree be used with TreeModel - MVC desing pattern

I am going to use JTree in my Java Swing Desktop Application. I read about MVC Design pattern and according to it, we should use Model classes of Swing Components to separate the datamodel of a JComponent from its presentation part. So my quick question is as follows: JTree(TreeModel newModel) JTree(Object[] value) JTree...

Java Swing positioning elements differently in different operating systems.

I have written a Java Desktop Application that runs in Windows, Mac OS X, Ubuntu and Open Suse. I am having issues with is positioning thing differently in Linux. I developed the application with NetBeans using the designer, it looks as I would expect in Windows and Mac OS X, but in the Linux distros certain label controls have shifted ...

Making BoxLayout move components to top while stacking left to right

Hi, I have a JPanel which uses a BoxLayout in the X_AXIS direction. The problem I have is best shown by an image: As you can see the JPanel on the left is has been centered rather than aligned at the top. I would like them both to be aligned at the top and stacked left to right, how can I achieve this with this layout manager? The cod...

JRadio button with information link

I want to have a set of JRadioButtons and next to each one a little 'i' image which when clicked will open a new window with information about the text next to the radio button. What is the best component to use to align the little 'i' label next to the Radio button? ...

JSeparator wont show with GridBagLayout

I want to add a vertical JSeparator between two components using a GridBagLayout. The code I have is as follows: public MainWindowBody(){ setLayout(new GridBagLayout()); JPanel leftPanel = new InformationPanel(); JPanel rightPanel = new GameSelectionPanel(); JSeparator sep = new JSeparator(JSeparator.VERTICAL); Gri...

How to keep mainframe behind dialog when switching top-level windows?

Following situation: I have a JFrame and call JOptionPane.showInputDialog("test"). The modal dialog will be shown. When I then switch to another open window in Windows (let's say Firefox) and then return to my Java application (by clicking the tab in the windows task bar or with ALT+TAB) then only the dialog will be shown. Is it pos...

Focus traversal between two tables in a Panel.

I have two (5 * 1) tables to be shown as a single table on UI. How can I get a focus traversal mechanism for the two components(table) which mimicks the behavior of single ( 5 * 2 ) table. ...

setting layout of output windows in netbeans

Hello all, Is there a way to set the location of the output windows even before running.. My project has more than two forms , and i would like to display them in a non-overlapped fashion , and set their layout beforehand. ( I'm using netbeans..) ...

Java: how to register a listener that listen to a JFrame movement

How can you track the movement of a JFrame itself? I'd like to register a listener that would be called back every single time JFrame.getLocation() is going to return a new value. EDIT Here's a code showing that the accepted answered is solving my problem: import javax.swing.*; public class SO { public static void main( String[] ...

Drag and drop with an image

I need to create a drag and drop system in swing where an image of the thing being dragged is attached to the cursor during the drag. In theory this is achieveable with public Icon TransferHandler.getVisualRepresentation(Transferable t) but there appears to be a long standing bug (here) that means this method is never called. I know ...