swing

Selection of embedded items in a JTextPane

A JTextPane lets you embed JComponents and images. When you select a section of the document the text is highlighted but the embedded items are not. You can have the embedded components notified by way of a CaretListener after the event, but I was wondering if there was a way to have them highlighted during mouse selections? ...

How to change JFrame Icon

I have a JFrame but it displays a Java icon on the title bar (left corner). I want to change that icon to my custom icon. How should i do it ? ...

JMenuItem accelerator not working after showing two non-modal JDialogs? (Mac only?)

I have the problem that the accelerators of JMenuItems aren't working anymore after showing two JDialogs directly after one another. Please take a look at this small example that reproduces the problem: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DialogBug { public static void main(String[] args)...

JMS Queue to JTable Update [Now getting exception after changes]

I am writing my own JMS Browser and I am struck at the JTable update of Messages from JMS servers. I have tried AbstractTableModel TableModelListener to make Jtable refresh when the data added into LinkedList. This below logis works , but its not updating realtime , means I would like to display each and every row added to Jtable immedia...

Java print - page

Hello, My application allows the user to print the screen content which is made of several Swing controls (images, texts, etc.) - the printed panel it self is long (several pages) and the width about 600pixels. Since I know exactly each page layout (I put the exact number of images and components) on each page (the total number of imag...

How to set AUTO-SCROLLING of JTEXTAREA in Java GUI?

I have embedded a JTextArea on a JScrollPane and am using that JTextArea for output. I want that whenever the ouput goes beyond the size of the JTextArea, the JTextArea scrolls automatically so that user don't have to do manual scroll down to see the recent output. How can I do that? I have already set the autoscroll property of both ...

How to add multi-line label on a Java GUI ?

I have made a java swing GUI. Now I want to display a static message on that but the message is multi-line and the JLabel is single line. How can I display that message? Is there any property of JLabel which we can set to display the multiple line message? Will I have to use several JLabels for multiple lines? Is there any other way ...

Swing: Alignment Problem

Hi everyone, I have a question about laying out some swing components. Say, I have a JPanel which contains a JLabel and a JTextField. I want JLabel to be drawn on the left-most side of JPanel, and JTextField to be drawn on the right-most side of JPanel. I tried using BoxLayout and Horizontal Glues, but I couldn't make it work. Can someb...

Can panels communicate with each other?

I'm trying to call a method from a panel class, however it does not result in anything. Can panels communicate with each other? Or is there another reason why this isn't working? Calling the method name() in the leftInput class. ButtonPanel class. import model.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; publi...

Problem selecting the value from a JComboBox binded to a list

I have a JComboBox binded to an observable list (result of a jpa query) in a java desktop application. It gets all the values from that list and displays them correctly, but I'm not able to select any particular value from the dropdown: that is, when I click on the widget the list of options gets displayed correctly, when I click on an i...

how to add different cell editors for one column in JTable?

I have a JTable with two columns and both are JComboBox, for this purpose I implemented my own Model and overrode methods. One of the method which I overrode is: public Class getColumnClass(int index) { return JComboBox.class; } Also created my own ComboBoxEditor and ComboBoxRender classes, and set cellEditor and cellRenderer: c...

Java: JProgressBar

Hi, Is it possible to make a progressbar in Java like displayed on this page? Image.So, not the default progressbar "filling-way". If so, how? Thanks ...

What should qualify as a "long running task" to be executed in a SwingWorker thread ?

I know how to use SwingWorker threads, but I still don't have precise criteria to decide when to use one or not. I/O seems obvious, but what about methods operating on potentially large collections ? A criterion could be the actual running time, but what kind of number (in ms) would qualify ? ...

Is it possible to have 2 JPanels in a Border layout at the same location?

Hi All, I'm writing a game which uses a border layout with a JPanel using BorderLayout.CENTER. What I'd like to be able to do is sometimes hide this panel and replace it with another panel with different information. I added both to the container and set visibility of one of them to false. Then later I try: panel1.setVisible(false)...

Changing the background color of a paragraph in JTextPane (Java Swing)

Is it possible to change the background color of a paragraph in Java Swing? I tried to set it using the setParagraphAttributes method (code below) but doesn't seem to work. StyledDocument doc = textPanel.getStyledDocument(); Style style = textPanel.addStyle("Hightlight background", null); StyleConstants.setBackground(style, ...

How to generate a form file from existing code?

Hi! In netbeans you can choose to work on "design" or "source". If you don't have a form file, netbeans won't let you see the design and work on that with drag and drop. I have some existing code with much swing. How can I use the "design" mode in netbeans on that code? To me it seams I can only use the "design" mode if I create a new e...

Listening for new child components in Swing

I have a specific requirement that all children of a particular JComponent have double buffering turned off. I can recurse through it easily enough and disable them when needed, but I'd like to detect the addition of new children components regardless of their position in the hierarchy and disable it then. I've taken a look at addHiera...

How to prevent JScrollPane from scroll down on repaint?

Hi, I have got a JScrollPane with a diagram inside. The paintComponent Methode of the diagram is overridden. Now when the diagram paints itself, the scrollpane scrolls down to the buttom. How do I prevent the scrolling? I want the scrollpane / scrollbar to hold its position when painting. Thanks in advance. ...

Drag and drop between 2 Jtrees

In my application I have 2 JTree controls in a JPanel. How can I transfer data between them, so that the items from the source tree are removed. ...

JPopUpMenu problem with adding menu items

I'm creating JPopUpMenu with following code: JPopupMenu popup1 = new JPopupMenu(); JPopupMenu popup2 = new JPopupMenu(); JMenuItem freeze = new JMenuItem("freeze"); freeze.addActionListener(new FreezActionListener(this)); JMenuItem unfreeze = new JMenuItem("unfreeze"); unfreeze.addActionListener(new UnFreezActionListener(this)); JMen...