swing

JFileChooser select directory but show files

I feel like there should be a simple way to do this but I can't figure it out. I have a JFileChooser that allows the user to select directories. I want to show all the files in the directories to give the user some context, but only directories should be accepted as selections (maybe the Open button would be disabled when a file is selec...

Changing content of HTMLDocument displayed in a JTextPane

I'm displaying some tables as HTML code (rendered by a Freemarker template) with a JTextPane. I also have some HTML links in this HTML output which can be used to interact with the values of the table (For example "Delete a row" and stuff like this). Currently I always recreate the whole HTML output on each change and replace the whole d...

Swing layout - Using a grid while keeping component dimensions

I'd like to make a login bar for an application and I can't figure out how to organize a series of JLabels and JTextFields such that they are organized in a horizontal grid without these same components being resized to fit each cell. I also want to make sure that the group of components isn't resized below a certain width. How can this ...

How to get a handle to all JCheckBox objects in order to loop?

I'm very new to Java and am having some issues looping through JCheckBoxes on a UI. The idea is that I have a bunch of checkboxes (not in a group because more than one can be selected.) When I click a JButton, I want to build a string containing the text from each selected checkbox. The issue I'm having is that our instructor told us tha...

Does Java Mac OSX native look and feel respect UIManager font changes?

I have a java applet and the only look and feel that works properly is the native mac one. I wanted to make the fonts a bit larger and tried using the standard UIManager methods UIManager.put("Label.font", new Font("Georgia", Font.PLAIN, 18)); This produces no change. It does not throw an exception, of course. Does anyone know if the...

Java JList model

How can I make a list model from a JList in order to be able to insert an item into it. I want to use this method: addElement(java.lang.Object item) I found an explanation here, but the problem is that ListModel is an interface and even if I write an implementation and override its method, I can't use the addElement() method ...

NetBeans create and instantiate programatically custom swing widgets

Hey! I have a problem I know how I would solve easily developing under eclipse - but not so easily developing under net beans. I want to create a custom swing widget - which I can instantiate by code as many as I need and attach them to my main panel. I have developed the rest of the GUI using the GUIBuilder. The problem is - im ...

Removing JPanel from a JFrame in netbeans

So, I have several JPanels that contain buttons, labels, etc. that I want to switch between from a main JFrame. Currently I am trying to use the this.add(JPanelname); method and this.remove(JPanelname); with the validate(); and repaint(); methods The problem is it will add the panel to the JFrame but it will not remove it. I am not sur...

Colouring JTree's TreeNodes

I have a JTree which I give objects that implement the TreeNode interface, and a custom TreeModel to display them (not using DefaultMutableTreeNode). I would like to change the text colour of some nodes. I can't find anything in the docs, except javax.swing.tree.DefaultTreeCellRenderer.setTextNonSelectionColor(Color newColor), but it wil...

Frame Showing Problem

Hey Guys I have made one project which is showing the inventory of the stock of one store. In that inventory the software should store data of the products with their images. There is one problem... Bcz of the lots of stock, the screen on which is image is loading taking a lot of time. So, i thought i should give the frame in which there...

"Unsupported Image Type" exception in only few images...

In my java-swing project. I have one frame in which user can drop the images and save that images in database. Now this work perfectly but their are some images which is not showing. This are images Image 1 , Images 2 which is not supporting .. this are some images which are not reading... and its showing me exception, like javax.imag...

Add a listener inside or outside get method

I'm learning Swing and have composed an interface using a series of get methods to add components. Is it a good practise to add a Listener inside a get method as follows? I'd like to make things as decoupled as possible. private JButton getConnectButton() { if (connectButton == null) { connectButton = new JButton(); connectButt...

How can I control the width of JTextFields in Java Swing?

I am trying to have several JTextFields on a single row, but I don't want them to have the same width. How can I control the width and make some of them wider than others? I want that they together take up 100% of the total width, so it would be good if I could use some kind of weigthing. I have tried with .setColumns() but it doesn't m...

Difference between the Document classes

I've been reading the javadocs trying to grasp around the swing Document API but I cant get something sensible out of it because there's so many classes: Document, StyledDocument, AbstractDocument, DefaultStyledDocument, PlainDocument, HTMLDocument, and someone mentioned DocumentFilter. This question is more on a general basis so can som...

Custom Java Swing Meter Control

I'm trying to make a custom swing control that is a meter. The arrow will move up and down. Here is my current code, but I feel I've done it wrong. import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.LinearGradientPaint; import java.awt.Polygon; import java.awt.Stro...

Grouping swing objects

Hey. I want to make an object I can add to my java swing application. The object when instantiated would contain an image and 2 labels - is there a way to do this using java swing? If there is - can you point me at an example. I.e i want Myobj icon = new MyObj(pic, label , label); window.addComponent(icon); Cheers Andy ...

Unresponsive threading involving Swing and AWT-EventQueue

I have an application that is unresponsive and seems to be in a deadlock or something like a deadlock. See the two threads below. Notice that the My-Thread@101c thread blocks AWT-EventQueue-0@301. However, My-Thread has just called java.awt.EventQueue.invokeAndWait(). So AWT-EventQueue-0 blocks My-Thread (I believe). My-Thread@101c,...

Java/Swing: low-profile button height?

I would like to reduce the vertical size of a JButton. The following code works fine for K > 1 but I can't seem to reduce the size. Any suggestions? JButton button = /* ... get button here ... */ Dimension d = button.getPreferredSize(); d.setSize(d.getWidth(), d.getHeight()*K); button.setPreferredSize(d); edit: I'm using JavaBuilders ...

Generate event, Swing

How can I generate event MouseWheelEvent for some Object? ...

How to set jspinner as non editable?

I am creating time picker using the spinner.In that the text inside the spinner is editable.But i want to set the spinner as non editable.Because is there chance to give invalid value.Can any one help me.? ...