Skip to main content

JXTextField background weirdness

1 reply [Last post]
fommil
Offline
Joined: 2006-11-26
Points: 0

Hi,

I'm using the code (below) to generate a JXTextField with a prompt, setting the background colour to white. I then create a JTextField for comparison. Note that the rendered background colour is not white (OS X Lion).

When I then insert a value into the JXTextField, note that the background is now white but it is rendered outside of the text field area. (see images)

I see this with swingx 1.6.1 and 1.6.3. I believe it is a bug.

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.*;
import org.jdesktop.swingx.JXTextField;

public class Scratch {

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

        JXTextField jxText = new JXTextField("Prompt");
        jxText.setMaximumSize(new Dimension(300, 20));
        jxText.setPromptBackround(Color.WHITE);

        JTextField text = new JTextField("Prompt");
        text.setMaximumSize(new Dimension(300, 20));

        panel.add(jxText);
        panel.add(new JLabel(" "));
        panel.add(text);

        frame.add(panel);
        frame.setSize(300, 300);
        frame.setVisible(true);
    }
}
AttachmentSize
JXTextField.png10.84 KB
JXTextField2.png10.52 KB

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

I would guess that the AquaLookAndFeel is using some painting tricks on their border. We have the paint the prompt on the textfield giving it the same insets as the original, but with an empty border. I am going to guess that there is some Aqua custom code in their to draw that border that is not working 100% with our solution.

I don't have a Mac to test on, so I'll need help solving this issue. Please file one in the issue tracker (http://java.net/jira/browse/SWINGX) and we'll see what we can do.

Karl