swing

Java swing: Multiline labels?

Hi, I want to do this: JLabel myLabel = new JLabel(); myLabel.setText("This is\na multi-line string"); Currently this results in a label that displays This isa multi-line string I want it to do this instead: This is a multi-line string Any suggestions? Thank you EDIT: Implemented solution In body of method: myLabel.setTex...

Swing JPanel wont repaint

Hi, I have a simple object which extends JPanel, when the update() method is called on this object it it meant to add some labels to the panel and then repaint. However the labels do not show up after the update method is called, below is the code for update: public void update(){ GridBagConstraints constraints = new GridBagCons...

Can I create a JFrame with multiple images?

Here is my problem: I have an application that every iteration it returns to me a list of images. The imagens have different sizes and the number of images to be shown varies every time. Is there a way to show in a jFrame all the images without knowing the number of jPanels to create? Is there an easy way to do that? Obs.: The images ...

Customizing javax.swing.JFileChooser to include an additional JTextField

I want to include an additional (optional) JTextField in the FileChooser, allowing the user to fill it in while choosing the file rather than giving them an additional prompt after they make their choice. Has anybody attempted something similar and found a working solution? My target result would look something like this: http://imgur.c...

how to stop JPopupMenu show() from visually un-selecting the list item clicked on

Right now when a user right clicks on a selected JList item in my program the resulting JPopupMenu clears the selection (at least visually) until the popup menu is closed. This isn't consistent with the native look and feel of any platform I know of. The item should stay visually selected or have a selected-color border around it. But I ...

EventListenerList firing order

In a Swing application, I have a number of sub-panels, each listening to a single JSlider. The surrounding parent panel also listens to all the sub-panels. To get consistent results in the example below, I had to add the parent first and then the local listener. This makes sense, given the order prescribed in EventListenerList and explai...

JButton with text below the icon

In Java Swing I would like to create a JButton which contains an image(icon) and some text. In few words a JButton(text,icon). I would like the text to be displayed below the image, and not beside, as in normal JButton layout. Does anyone have an idea on how to achieve this? ...

How to adjust position of JButton if the parent JFrame is resized?

I have some JButtons in a JFrame. The layout of JFrame is null. i have given absolute position to button. But when i minimize or maximize frame, the postion of the buttons is getting disturbed how can i set it relative to JFrame dynamically? ...

swing: best way to make components enabled/disabled depending on the state of a model

I have a data model model which has a boolean flag connected, and I have a view with several components that I want to enable if model.isConnected() is true and disable if it is not. What is the best way to implement this? ...

Method sleep until event fired

Hi, I have a poker framework for which I am trying to develop a "player" for. Basically I am implementing an object that implements a Player interface defined by the framework. I am trying to put a GUI on top of this player, the way that game play works is that the Dealer invokes the act() method on my player and expects a return type o...

Re-paint problem on translucent frame/panel/component.

I'm trying to create a translucent window with Java on OSX and add a JLabel to it. This JLabel changes its text every second.... However the component is not repainting well. How can I solve this problem? I've found the these articles, but I can't figure out how to solve it. If possible, please paste the fixing source code, he...

Live tracking the number of selected items in a string

In Java Swing I have a simple table where in each row the name of the element and a checkbox is included. Users can select any of the elements contained by clicking in the associated check-box. I would like to have a string below the table that constantly keeps track of the number of elements selected (E.g. "3 elements have been selected...

Column moved [finished] event in JTable

How should I detect that column moved action is finished in JTable? I've added columnModeListener to my column model but the problem is columnMoved method is called every time a column moves (by certain pixels). I don't want this behavior. I just want to detect when the column dragging is finished. columnModel.addColumnModelListener(new...

Problem with GridBagLayout in Java Swing

I have a simple problem with my JPanel / Gridbaglayout: import javax.swing.*; import java.awt.*; public class gridfenster extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JButton b1=null; private GridBagLayout gbl = null; // i tried it without this line! ...

swing: appropriate Listener for JTextField change events

Which type of Listener do I use for listening to changed text events in a JTextField? (I should know this or be able to tell from the Javadoc but I can't seem to figure it out.) ...

Swing "blocking", I think I need to thread, but not sure how much

I have a little java app to effectively "tail" an arbitrary collection of files defined in an ini file. My "LogReader" class extends JFrame, and does the heavy lifting; reading the collection of file paths into a vector, and then iterating over the vector, reading each file and adding the last X lines of each to a text areas on the tabs ...

Java Textfield focus

hello i have a problem with the focus mytext= new JTextField(); mytext.requestFocus(true); gc.fill =GridBagConstraints.HORIZONTAL ; gc.gridx =3; gc.gridy=4; gbl.setConstraints(mytext,gc); jContentPane.add(mytext); i tried mytext.requestFocus(); too and how can i auto-select the text in the textfield so the text is marked? thanks...

JTextPane Synchronize Style Selection UI Problem

I am developing a simple WYSIWYG RTF editor in Java and have a small issue. I need to be able to synchronize the style selection toggle buttons (such as bold, italic, underlined) to the users text selection. For example, if the current text selection is plain, the bold, italic and underlined toggle buttons are not selected, but when the ...

JSplitPane giving wrong resize cursor with GTK LAF?

Running the official JSplitPane demo http://java.sun.com/docs/books/tutorial/uiswing/components/splitpane.html on my Ubuntu system gives a resize cursor like --> over the divider. The behavior of native split panes gives <--> resize cursors. Does this qualify as a bug that should be reported to Sun (eh, Oracle)? Is there a workaround? ...

java mouseadapter source not found

I have an array of JPanels and I'm trying to add a mouseadapter to each one so it will be possible to identify which one was clicked and then change its background colour. Everything seems to work fine except when I run it from eclipse when a page will appear that says EventDispatchThread.run() line: not available, Source not found, and ...