swing

Correct way to use Actions to create menus, toolbars, and other components in Java

The naive way of writing building a menu in a Java Swing app is to do something like: JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open..."); openItem.addActionListener(new ActionListener() { /* action listener stuff */ } ) fileMenu.addMenuItem(openItem); A more experienced developer will recognize that acti...

Tabs with equal (constant) width in JTabbedPane

I'm trying to get a JTabbedPane where all tabs (the actual tabs, not the components) have the same width (either the minimum width needed for the widest label or a constant width). I've tried to override BasicTabbedPaneUI.getTabBounds(int tabIndex, Rectangle dest), but apparently this method isn't used by the painting methods of BasicT...

Is it possible to set a TitledBorder opaque on Swing?

Is it somehow possible on Swing to set a TitledBorder transparent so that a background image shines through? ...

Java: Swing --> Maximize window

I'm putting together a quick and dirty animation using swing (hehehe). I would like the window to be maximized. How can I do that? Thanks in advance :) ...

Java Swing: Mouseover text on JComboBox items?

In Swing, is there a way to define mouseover text (or tool tip text) for each item in a JComboBox? ...

Java: Handle logoff or shutdown on Windows and Linux

Is there a way for a Java GUI application to respond to system shutdown or logoff events, other than to use JNI? (On Windows, the JNI would use WM_QUERYENDSESSION, on Linux?) The method should allow the program to prompt users to save, etc., and then continue the logoff process. ...

Help with annotations

Edit--@Uri correctly pointed out that this was an abuse of annotations; trying to actually create the menu data itself in annotations is just silly. They are good for binding however, I think I'll stick with using them to link the text data to the methods (the @Menu ("File") portion) since it's more explicit and flexible than reflecting...

How can a JComponent notified about the closed event of it's parent J(Internal)Frame?

I want to write a component that monitors other activities, but it's listeners are to be removed when the component's window is closed. I don't want to write this removal code many times, but want the component to handle it itself. (How) can i do it? Thanks! ...

How to select first item in JPopupMenu?

In the past, when one made a JPopupMenu visible it's first item would get selected by default: http://weblogs.java.net/blog/alexfromsun/archive/2008/02/jtrayicon_updat.html Nowadays the default behavior is to pop up the menu without any item selected. I would like create a JPopupMenu with a single item that will pop up selected and cent...

How can I travese to a next / previous page in a swing GUI

Hi All, I am new to Swing. I am trying to develop an application using Swing. I have managed to create the first page of my application. Now what I want to do is to traverse to a new page, using the next button. But am not able to find a way to do it using Swing. Also, if I click the previous button, would I be able to get the data that...

How could I implement autocompletion using Swing?

I'm interested in providing an autocompletion box in a JFrame. The triggering mechanism will be based on mnemonics (I think), but I'm not really sure what to use for the "autocompletion box" (I would like results to be filtered as the user presses keys). How would you implement this? Some sort of JFrame, or a JPopupMenu? I would like ...

Using swing how can I flash the Windows Taskbar

I'm developing a swing application and I need to flash the windows task bar. I can't use frame.requestFocus(); because I don't want to steal focus from any other application. ...

Can a layout manager spawn several JPanels?

I have to build a rather large form with many controls. The controls are divided in basic controls/settings and extended controls/settings. The user can decide if he wants to see only the basic or both basic and extended controls. I've dropped all extended controls onto their own JPanel so that I can easily switch between the two views ...

Is it safe to construct Swing/AWT widgets NOT on the Event Dispatch Thread?

I've been integrating the Substance look and feel into my application and ran into several problems regarding it's internal EDT (Event Dispatch Thread) checking routines. Substance absolutely refuses to construct UI classes outside of the EDT. I've done plenty of Swing/AWT and I know most of the rules regarding the EDT. I use SwingWorker...

can I build swing applications on eclipse ?

I used to work on netbeans to build Java applications but now: i am using eclipse. I was was wondering if there a a free good plug-in to help me with swing windows.?? ...

Tab character in Java

Hi guys, Trying to get a tab character into a JMenuItem using \t but it's not printing. I bet it's something really basic I'm missing. Here's the code menuItem = new JMenuItem("New\tCtrl + N"); Thanks ...

How to avoid negative values with JFreeChart fixed auto range

I have a JFreeChart line plot that is updated dynamically with one data point for every iteration of my algorithm. Because the number of data points can quickly become very large, I have used the setFixedAutoRange(double) method on the domain axis. This restricts the graph to displaying the n most recent iterations (200 in my case). T...

How to create a scrollable JPopupMenu

I am trying to create a JPopupMenu that has a scrollbar so that I can display a large number of items. There are a couple of implementations on the web that all have problems: http://forums.sun.com/thread.jspa?threadID=5128630 Looks correct (except for issues with separators) but if you scroll it the highlighting and selection no lo...

skeleton app for swing

I'm starting a simple project in swing but i don't want to start from scratch i'm searching a basic starting point with toolbars, file menu and basic functionality that works (exit from the application, button toolbar with a simple actionListener ...). I know there are eclipse rcp and the netbeans one but they are too big for my project....

JPanel in JFrame in NetBeans

I have created a Java application (project) in NetBeans, in which I have designed a JFrame with menu bar, and different JPanels. I want these JPanels to appear inside the JFrame on action of different menu items, so that whenever the menu items are clicked different JPanels should appear inside the JFrame. I have designed both JFrame & J...