swing

How can I listen for keyboard input? such as arrow keys?

Hi, what is the easiest way to listen for key presses from the user? Specifically I am writing an image viewer program that uses a JFileChooser to select images and on the left side, a JList that shows the contents of the director. I would like to make the arrow kets (left/right) move to the next/previous file. Thank you in advance. ...

Wrong JTableHeader component orientation with RIGHT_TO_LEFT + AUTO_RESIZE_OFF in JScrollPane

Using Swing on Java 6u16, WinXP SP3 Hello to all. I need some help, please, with the following case. Basically I use a JTable inside a JScrollPane, that on the scrollPane I apply component orientation of right-to-left. The final result that I get is such that the table is indeed is attached to the right, but the header is placed to the ...

MouseListener for JPanel missing mouseClicked events

I have a JPanel that I have created a MouseListener for and I am seeing some behavior that I can't explain. Usually when I click the mouse within the JPanel, I see the following events fire: mousePressed mouseReleased mouseClicked On some occasions, I don't see the mouseClicked event fire, I only see: mousePressed mouseReleased I...

OS X: How to speed-up Java/Swing GUI?

I have a Mac mini with 2GHz-Core2Duo/2GB RAM and a HP-Notebook running Windows 7 with identical hardware. For our Java desktop application I'm using Quaqua and Windows look and feel, respectively. On OS X the whole application feels much more sluggish than the one running on Windows 7, especially the rendering. Are there some options fo...

how to get size of panel based on the size of graphics put on it

I am writing program which draw table by drawing multiple rectangles. The row and col of the table are set at run-time. So how do i know the size of the jpanel to display the table? ...

SpringLayout works on Windows 7 but not NetBSD?

I am making a GUI using SpringLayout using the following code: private void createAndShowGUI() { frame = new JFrame("A GUI"); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setResizable(false); Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); cont...

JTable - compound editor focus

I have a custom editor composed of several components. Something like: class MyCellEditor extends AbstractCellEditor implements TableCellEditor { JTextArea textArea; JButton button; JPanel panel; MyCellEditor() { textArea = new JTextArea(); button = new JButton(); panel = new JPanel(new BorderLay...

How to override JTextArea isEnabled() method

I want to override isEnabled() method in java.awt.Component and use it with a JTextArea. This is what I do. This code snippet is called inside the Jframe constructor. jTextArea1 = new javax.swing.JTextArea(){ @Override public boolean isEnabled(){ if(getForeground()== new Color(0, 0, 0)){ ret...

Is it possible to port Swing into .Net world?

My question is it possible to port Swing into .Net world? Or a project like this has already been started. If it is not possible, can anyone please shed some light on the reason? ...

Issues with add JButton in the table

I am adding Jbutton to a table by extendibg AbstractCellEditor class. But on click of button the text doesnt change from "Start" to "Stop" .here is the class i implemented public class ButtonEditor1 extends AbstractCellEditor implements TableCellEditor,ActionListener,TableCellRenderer{ JButton btnSTART = new JBu...

Swing - how to grab focus *now*?

How can I instruct my Swing component to grab focus right now? requestFocus() doesn't seem to be dispatched instantly. Ideally, I would like this (ran from EDT): textInput.requestFocusInWindow(); System.out.println(textInput.hasFocus()); To print true. Below is the SSCCE. Notes/requirements: Table is navigated with keyboard. Colum...

Sliding viewport over a JPanel

I'm using drawLine() and friends to paint a graph onto a JPanel. There are tens of thousands of points to graph, so it takes 3-5 seconds. I want to have a viewport, like the blue one illustrated below, over the graph. I would like this viewport to be updatable, as I have a MouseMotionListener on the JPanel that the graph is on. The pr...

Smart JScrollPane autoscrolling

I am attempting to implmement smart autoscrolling on a JScrollPane containing a JTextPane. The JTextPane is used for logging my app in color. However I'm running into a wall trying to do smart autoscrolling. By smart autoscrolling I don't mean blindly autoscrolling every time something changes, I mean checking to see if your scrolled all...

Trouble with BufferedImage & ImageObserver in Clojure/Swing/Java

I've been trying for hours to get my drawing method to work by drawing in a BufferedImage stored in a Clojure ref, and then to have that painted onto the component (in this case a JPanel) in order to display it. Unfortunately, this isn't working well at all. My code is this (pared down, but showing the relevant parts: (defn create-gra...

Java's FlowLayout does not resize correctly

I created a JFrame initialized with a BorderLayout and a JScrollPane as its CENTER element. The scroll pane is set with VERTICAL_SCROLLBAR_ALWAYS and HORIZONTAL_SCROLLBAR_NEVER policies. The intent of my frame is to have a controlled width, while the height should grow/shrink as data is added/removed. Inside my scroll pane, I added a ...

Manual Compile of Netbeans Java Swing Application Created Multiple Classes

Hi. I created a Swing GUI using netbeans, and when I try to manually do the following: # ls myProg.form myProg.java # javac myProg.java # ls myProg$1.class myProg$2.class myProg$3.class myProg$4.class myProg$5.class myProg$6.class myProg.class myProg.form myProg.java It created those extra classes. Why is this happening? Is th...

How can I press a swing JButton using mouse events?

I Have a JButton (or any Component, really) that I would like to trick into thinking that it has been clicked on and therefore firing its action performed event. I don't want to call the action performed or doClick directly because I am trying to make a solution that generalizes beyond buttons, and I am constrained to posting events. I ...

Cannot get image to display in Swing on OSX

Hi chaps, I think I'm being a bit of an idiot, given that I haven't done Swing programming in a while, but I'm trying to draw a simple image to screen, and I'm not getting what I expected public class ImageApp { public static void main(String[] args) throws MalformedURLException, IOException { final Image image = ImageIO.re...

How to rotate an image gradually in Swing?

I have an image I am rotating when the user clicks on a button. But it is not working. I would like to see the image rotating gradually to 90 degrees till it stops but it doesn't. The image must rotate 90 degrees gradually when the button is clicked. I have created an SSCCE to demonstrate the problem. Please replace the image in the Cr...

JTree set handle visible on first node level when root is not displayed

I have a JTree like this: MasterRoot +-RootA +-ChildA1 +-GrandChildA1a +-RootB +-ChildB1 +-GrandChildB1a I don't want the MasterRoot node to be displayed But if I call `configTree.setRootVisible(false); I got: RootA +-ChildA1 +-GrandChildA1a RootB +-ChildB1 +-GrandChildB1a And I want this: +-RootA +-ChildA1 +-Grand...