swing

How do I create a component that auto-sizes in the Borderlayout North Position

I want to create a JLabel (containing an image) in the north position of a border layout that auto-sizes to a length matching the preferred width of a component in the center position of a border layout. The only way I can do this at present is to create another panel in the north position and add the label in the center position of thi...

What is the "good way" to subscribe to value changes in a JFormattedTextField?

I want to subscribe to value changes on a JFormattedTextField. Checking the source code, the only thing I see is that the property "value" is fired on a new value. But this property is only referenced there, and directly written, without a constant. If I subscribe to this property change, it works. However, I'm wondering: is this the...

Logback+Swing in small tool

I need to hack up a small tool. It should read a couple of files and convert them. Right now that works in my IDE. For the user, I'd like to add a small UI which simply shows the log output. Do you know of a ready-to-use Swing appender for logback? Or something which redirects System.out to a little UI with nothing more than a text fiel...

Under Netbeans/Java Swing, how do I run the program as GTK+ Look and Feel?

Hi all. I've been trying to Google this answer with no results. I keep on finding answers on how to make Netbeans run in a GTK skin .... this is NOT what I want. I have a Java Swing application. I can preview it under GTK+, C/X Motif perfectly fine when I right click the JPanel Form --> Preview. However, whenever I try to run the pro...

How can I keep columns of a JTable from resizing when I resize the JFrame?

This code puts a JTable into a JFrame (sole component of the whole UI): JFrame frame = new JFrame( "Title"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = appender.createTable(); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); frame.getContentPane().add...

convert the output of PinField.getPassword() to string

if ("Submit".equals(cmd)) { //Process the password. String UserNameInput=UserName.getText(); ///////////////////////////////ERROR Pin when printed shows error///////////////////////////// char[] PinInput = PinField.getPassword(); String pinInput=PinInput.toString(); //for debugging , print PinInput , b...

JList Help Please

Hi Guys, I have a list of data in a JList component in my GUI. I would like to know if there is a method that i can call on the list element(s) to strike through a particular element in the list. I would like to draw a line through the element to appear as if that element is canceled. I want a similar thing like the strike through fun...

How to obtain bounding box of transformed text(java)?

Currently I have a text object that I need to determine its bounds. I used to use the graphics object to obtain the font metrics of the text I am trying to draw, but since I added functionality to rotating the object(and possibly more) I need a better way to get the bounds of this object. I have looked multiple places and nothing has rea...

Drawing Java 2D Charts span across multiple views or panels or horizontal-scrolling

Hi I'm drawing a graph using Java 2d graphics (i.e. drawing and filling rectangles) straightaway on a JFrame from a set of values stored in an Arraylist. But when the ArrayList has very large number of values (can even go upto 3500 in size), the drawing is compressed - where the graph seems less informative and even the labels on the X...

JTextArea as listener for log4j Logger

How can I set up a JTextArea to receive anything that I log (short of creating an interface such as "MyLoggerListener" and implementing it into my JTextArea) EDIT: I fixed this problem by creating a TextAreaOutputStream, making a printwriter with it, and adding a WriterAppender with the printwriter in the constructor. ...

Design patterns to reduce coupling in Swing application

Hey all, I'm currently working on a Java Swing application and I was looking for some guidence. The application is fairly small, but I'm noticing that as the code base is growing larger, that I have an awful lot of coupling in my object graph. I'm relatively new to Swing, but I've been programming long enough to know where this is headed...

Scala - menu bar only appears when window contents revalidated

import scala.swing._ import swing.event.{WindowClosing} import java.awt.Dimension object MenuBarTest { def main(args:Array[String]) { val frame = new Frame() { visible=true contents = new Panel() { preferredSize = new Dimension(600,400) } title = "Test" reactions += { case WindowClosi...

Swapping values around in the view with information taken from a DAO

To respect requirements, I've temporarily used a hack to swap around a numerical id with a String representing a corresponding username in the view. To do this I've called a DAO directly from a TableModel. Obviously, this isn't very elegant and is probably inappropriate from a design point of view. What would be the proper approach to a...

Java Swing properties (addPropertyChangeListener)

Is there a published list of property names for Swing components? From looking at the source code for javax.swing.table.TableColumn, I can find calls to firePropertyChange with property names like "modelIndex", "identifier", "headerValue", etc. as hardcoded Strings, not as String constants. As far as I can tell, the only way to know wha...

How can I fix the column in JTable so that the column is always visible

How can I fix the column in JTable so that the column is always visible ? If I use JViewport than for the first time table is coming correct but when I click btn for the second time the next column in the Jtable is made fixed this continues each time. ...

1 pixel table border in JTextPane using HTML

I'm using a JTextPane to display some HTML that contains a table with a border. I want it to have a simple 1 pixel border. I tried using style="border: 1px solid; border-collapse:collapse". This works in a web browser, but not in JTextPane. Is there any way to have a simple 1 pixel table border using HTML in a JTextPane? ...

Java Swing - KeyListener

How can I know when the key typed change my text? Or if the key is a char? ...

Swing: Steal focus from other apps (usability in OS X)

I have an application in java swing which runs in the system tray most of the time. The user can use the Tray Menu to perform several actions. One of those actions is to show the app window. The problem I have is with usability on OS X. In windows, if the user brings up the app window and later switches to another app, they can switch b...

Java + JCommon: How set cell background in SortableTable?

How set cell background color in SortableTable? ...

Using an empty file to have one application instance

There's probably other ways of doing this but I'd like to use an empty file to have one instance of an application running at a given time. This would be done by creating the file when the application is launched and have other application instances exit as soon as they detect the file. The trouble with this approach is that the file ca...