swing

Showing the most recent opened items in a menu bar

I want to create a window with Java Swing. The window will have a menu bar with a File->Open button from where the user can select a file from hid hard drive. The File menu should also have a list of the most recent opened items, like many other applications show. Does anyone know what is the best approach? ...

JFileChooser returns incorrect path in OS X (folders only mode)

I have a problem in java swing where the user has to select a folder, so I am using the code below. JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if(fc.showDialog(singleton, SELECT) == JFileChooser.APPROVE_OPTION) { File folder = fc.getSelectedFile(); String path = folder.getPath() + ...

Operations on Java Swing

In my project,I will get the coordinates of some points from an XML file,and create some visual components using this information ? I am planning to give these components to a Java swing frame or panel. However,The users are supposed to click on the figure(which I will construct using Graphics 2d libraries) and select two points and give...

Image not getting displayed on a JPanel.

class Deal implements ActionListener { public void actionPerformed(ActionEvent e) { dl.setDeck(); dl.shuffle(); dl.firstDraw(pl); for(Card c:pl.showHand()) panelplay.add(new JLabel(c.getImageIcon())); panelplay.validate(); } }...

[hibernate - jpa ] good practices and bad practices

Hi all, i have some questions about interaction with hibernate. openSession or getCurrentSession (without jta, thread insted)? How mix session operations with swing gui? Is good have something like this in a javabean class? public void actionPerformed(ActionEvent event) { // session code } Can i add methods to my entities that c...

Gui problem after rewriting to MVC

I'm practicing MVC style programming. I have a Mastermind game in a single file, working with no problems (maybe apart of the fact that "Check" button is invisible at start). http://paste.pocoo.org/show/226726/ But when I've rewritten it to model, view, controller files - when I click on empty Pin (that should be updated, and repainted...

[Java2D] Is this bad practice? Multiple Graphics2D Objects

I've created a JPanel canvas that holds all graphics; namely JLabel. To get animated sprites to work you have to over ride the paintComponent of the extended JLabel class. I've successfully implemented animated sprites this way. Is it bad practice to have a Graphics2D canvas and then have multiple 'images' in their own Graphics2D? ...

swing: making a JProgressBar with a label superimposed on it?

I would like to use a JProgressBar and augment it to print its current value as well as the graphical bar. I'm guessing the best way to do this is to override paintComponent: @Override protected void paintComponent(Graphics g) { // Let component paint first super.paintComponent(g); // paint my contents next.... } but I am not...

JWindow with Black Opacity

I would like to create a JWindow that's not only has an opacity, but I want to change the default color of the opacity within Swing. So for example, if I write: AWTUtilities.setWindowOpacity(this, 0.5f); This will make do exactly what I want with one exception, the color is white. How can I make the color become black? I've tried ev...

Instructions Package for Java

I want to make a help/instructions page for my Java program but I really don't want to have to go through and program all the frames and searching and such. Is there a package or program that I can just insert the data into and it will read it and create the dialog? I couldn't seem to find anything about it on Google. It doesn't have ...

Java AbstractAction sometimes not detecting escape key - bizarre behaviour

In a master/detail view I have a series of text fields (and one or two other controls) that all pertain to the detail of the currently selected item. They all share the same DocumentListener so if you change any of them a pair of "save"/"discard" buttons become enabled. The buttons invoke a method and I can happily save/discard items. H...

Patterns for screen dynamics, GUI

Hi there, I code Java/Swing based UI. My dialogs are quite complex and there are many rules for screen dynamics: when to enable/disable buttons, when to allow to edit some fields, etc. In general there are widgets and there are some rules to set them in some state. I am wondering if there are any nice patterns, ideas how to resolve suc...

Control spacing in Swing

Are there guidelines for how much space controls in Swing should have around them? Also there is the question on how exactly to achieve that: Some layout managers have support for gaps between controls; some don't, where you then have to use EmptyBorder – which can be a pain as well since borders don't overlap and you may end up with too...

Swing add new Component

I need to add dynamicaly Components to JPanel, but if i make just add(Component) then component doesn't appears, if i make then JPanel.revalidate(); then it appears, but JPanel blinks, can I make it more fine, without blinking? Hm, i have found solution,just after add(component); i have write component.repaint(); and it works, but now t...

java desktop application - JList selection change does not update the interface

As I said, i have a java desktop application. The interface contains a JList and I modify the content of this list in some custom listeners that i implemented. One of the listeners iterates through all the items in the list and performs some operations that may take a while. I would like to show the user the item that I am currently at....

Where do i implement the main() function in a Swing program?

I was just curious where i should place the main function in a Java Swing program. It seems as If it's just way too short too create a brand new class for. ...

setSize not influencing size of button

I have a sample code : import java.awt.*; import javax.swing.*; import javax.swing.border.BevelBorder; public class AWT extends JFrame { public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setPreferredSize(new Dimension(600, 450)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_...

How can I integrate an external word processing application with a Java Swing app?

Hi all, I need some genius advice on this one. I have a Java Swing application that needs to launch a word processor in order to allow the user to complete some work, and then retrieve the output of that work and evaluate it later. In my head I am thinking my application can look in the normal places for Open Office or Word executables...

JPanel in puzzle game not updating

I have a simple puzzle game. There is an image consisting of 16 tiles (randomly placed). Images are stored in an array and when game is launched they're added to main JPanel. Game works in this way : Each image has atributes 'place' and 'number'. 'Place' is the current place on grid (either correct or not) and 'number' is the desired ...

Java - How to reset JLabel constraints after initializing it ?

I initialize a JLabel in Java frame like this : contentPane.add(myLabel, cc.xywh(1, 1, 31, 6, CellConstraints.DEFAULT, CellConstraints.BOTTOM)); But before showing the JFrame i make a small condition which if returns true i want to set myLabel to be set to DEFAULT instead of BOTTOM, but i can't find anyway except redefining it again l...