swing

Is it possible to place the header row of a JViewport at the bottom?

I'm using a JViewport for viewing some data and I'd like the header row to be placed at the bottom of the JViewport rather than the top. The viewport never scrolls horizontally so the issue of where the scroll bar would go isn't a problem. I suspect I'm going to have to make my own JViewport-like class which has the header row at the b...

Can I use printComponent without having to draw component to screen first?

I have been using the printComponent that was shown in another question. It works great for printing a JPanel if I first add that JPanel to a JFrame and draw that JFrame to screen. But if I don't do that before I print, I get a blank page printed. Why is this? Thanks in advance for any help. ...

Java default form action or button

Hi, In HTML forms, if you press 'enter' while in a text field the form will generally submit. I'm implementing a search panel in Java Swing, and I want to include the same functionality as I think users will be expecting this. I know that it's possible to use setAction on a JTextField to accomplish this, however I was wondering if the...

Nested JPanel resizing problem.

I have two JPanels (let's call these Panel1 and Panel2). These panels are of the same width, but varying heights. I want to put these JPanels into one big JPanel (lets call it Panel0), and stack them on top of each other (I decided to set Panel0's layout as GridLayout(0,1)). The problem, is that both nested panels (panels 1 and 2) end...

questions on "virtual trees" (custom TreeModel) in Swing

OK, I couldn't really find a decent example for a custom TreeModel in Swing that uses more than the basic features, so I wrote my own (code follows below) so I can ask questions about it, rather than about a more complicated application that's the one I really want to write when I understand how to write it. Apologies for the fact that t...

overriding JTree double-click to prevent node expansion?

It looks like there are 2 default mechanisms to expand a folder node in a JTree. One is to click on the expanded/collapsed icon next to a node. The other way is to double-click on the node itself. Is there a way to stop this 2nd mechanism? I would like to override the double-click on a node so it does something (updates another display ...

How do I add components to a JPanel at runtime

Hej I have a JPanel that I want to add some components. in particular JButtons to at runtime based on the content of a user supplied file. I can add compontents to panel if I call it from the constructor of the JFrame derived form class, even after everything else have been constructed, but If I read the file first and then add compone...

JTree with checkboxes

I need to add checkboxes to a JTree. A custom TreeCellRenderer/TreeCellEditor seems like the right approach. So far I used the CheckBoxNodeRenderer approach in this webpage. It works OK except for two things: there's additional whitespace above + below the checkbox; I'd like to keep it the same as a regular JTree. I would like to disti...

How to make my GUI work

Can anyone tell me on how the swing components drawn from the palette and put into the Jfame can work together? For example If a button pressed can the result show on the textArea, Or Can I drag some listed objects from the Jlist in my JFrame onto the JtextArea/JTabpanel? Thank you! ...

Component that can serve as an editor pane

Thanks for your answers to my questions some minutes ago! Can anyone tell me which swing component can perform same function as the editor pane of Eclipe or netbean when drag into the Jframe? For example, a swing component on which I can write/display codes and the same time can display some design when the button is pressed. ...

<br>? \n? a line break in java

I have three JLabels and three JTextAreas. I have them in borderlayout, center, but I want each of them in a different line, that's not happening and the top ten search results in Google for line break java don't solve the problem. How can I do a simple line break? ...

swing: saving dialog box resize dimensions

I have a dialog box with a bunch of dimensions that a user can change by moving/dragging, including a JTable with resizable/draggable columns. What I would like to do is to make the state of these resizable columns / dialog boxes / etc. persistent, so the next time my application starts up, the user doesn't have to go through the resizi...

alternatives/improvements to JSplitPane

I had a fairly simple dialog with a pair of JPanels of roughly equal size, contained in a JSplitPane. Now I'm looking at adding a 3rd JPanel and I'm not so sure there is an obvious solution. Is there a good window-docking framework out there? or is that a horribly complex thing to get into? If I do just stick with the 3-panel split, do I...

How do I remove component from JFrame that uses BorderLayout.

The container uses a BorderLayout. I have a JPanel that I added to the CENTER. However the JPanel doesn't have a variable name for it. I could do contents.remove(nameofPanel) But since I added it like this contents.add(new CustomJPanel(), BorderLayout.CENTER); Now I'm trying to remove the current CustomJPanel and add a new one. How d...

What's the easiest way to show a Windows Explorer-type file structure in Java Swing?

I thought I'd ask in case someone else has run into this before. How would you go about showing the user's file directory structure in a Java applet, something like Windows Explorer? Would I have to create a JTree and manipulate that, or is there an easier way? ...

Setting up application wide Key Listeners

How do i setup application wide key listeners (keyboard shortcuts), so that when a key combination (e.g. Ctrl + Shift + T) is pressed, a certain action is invoked in a Java application. I know keyboard shortcuts can be set JMenuBar menu items, but in my case the application does not have a menu bar. ...

Create a Mac OS X Style Dock Bar in Swing

Hi all, I want to create a Mac OS X style Dock Bar to be placed at the bottom of a JFrame. Does anyone know how I can do this? ...

How to programmatically close a JFrame

What's the correct way to get a JFrame to close, the same as if the user had hit the [x] button, or pressed Alt+F4 (on windows)? I have my default close operation set the way I want, via setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); and it does exactly what I want, with the aforementioned controls. This question isn't about that. ...

Bringing tab to front in JTabbedPane

When I use setSelectedComponent or setSelectedIndex on a JTabbedPane object, the panel always comes up in my UI. However, sometimes the tab associated with the panel remains hidden. In other words, the tab does not scroll to a visible portion of the tabbed pane. How can I fix this? I have tried the cheesy select one index, then selec...

How can I wait until a component is shown in Java?

Hi, I have a component (JPanel) inside a Window. I always get false when calling panel.isShowing(), when calling from a windowGainedFocus() event (when the parent window gets focus). I assume that when the windowGainedFocus() event is called, the painting of the JPanel within this Window had not been finished yet. I was trying to plac...