Losing part of the first character in a text field

Hi

Hoping someone can help me with this. I have a number of text fields which I populate with data from a database. When I do so I find I'm missing part of the first character in the text field. I've tried setting the margins on the text field using

UIManager.put("TextPane.margin",new InsetsUIResource(10,10,10,10));

but still get this problem. The way I currently solve it is to add a space at the beginning of the string and although this works, it isnt the most ideal solution.

Could anyone help or shed some light?

If necessary the code below produces the same effect. Mainly in the area name text field. In my main code I also use JGoodies FormDesigner and FormLayout but as I've replicated the effect without these I dont think they're responsible.

Thanks in advance

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.SwingConstants;

import javax.swing.UIManager;

import javax.swing.plaf.InsetsUIResource;

/**

* @author Andrew Dickinson

*/

@SuppressWarnings("serial")

publicclass BaseDataFormextends JFrame{

public BaseDataForm(String AreaName, String AreaRef){

try{

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

UIManager.put("TextPane.margin",new InsetsUIResource(10,10,10,10));

}catch (Exception e){

e.printStackTrace();

}

initComponents();

areaNameText.setText(AreaName);

areaRefText.setText(AreaRef);

}

publicstaticvoid main(String[] args)

{

BaseDataForm baseData =new BaseDataForm("Area Test","1234");

baseData.pack();

baseData.setVisible(true);

}

privatevoid initComponents(){

dialogPane =new JPanel();

contentPanel =new JPanel();

areaNamePanel =new JPanel();

areaNameLabel =new JLabel();

areaNameText =new JTextField();

panel1 =new JPanel();

areaRefLabel =new JLabel();

areaRefText =new JTextField();

buttonBar =new JPanel();

okButton =new JButton();

cancelButton =new JButton();

//======== this ========

setTitle("Base Data");

Container contentPane = getContentPane();

contentPane.setLayout(new BorderLayout());

dialogPane.setLayout(new BorderLayout());

areaNameLabel.setText("Area Name:");

areaNamePanel.add(areaNameLabel);

areaNameText.setHorizontalAlignment(SwingConstants.LEFT);

areaNamePanel.add(areaNameText);

contentPanel.add(areaNamePanel);

areaRefLabel.setText("Area Ref");

panel1.add(areaRefLabel);

panel1.add(areaRefText);

contentPanel.add(panel1);

dialogPane.add(contentPanel, BorderLayout.CENTER);

//- okButton -

okButton.setText("OK");

okButton.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

okButtonActionPerformed(e);

}

});

buttonBar.add(okButton);

//- cancelButton -

cancelButton.setText("Cancel");

cancelButton.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

cancelButtonActionPerformed(e);

}

});

buttonBar.add(cancelButton);

dialogPane.add(buttonBar, BorderLayout.SOUTH);

contentPane.add(dialogPane, BorderLayout.CENTER);

}

privatevoid okButtonActionPerformed(ActionEvent e){

this.setVisible(false);

}

privatevoid cancelButtonActionPerformed(ActionEvent e){

this.setVisible(false);

}

private JPanel dialogPane;

private JPanel contentPanel;

private JPanel areaNamePanel;

private JLabel areaNameLabel;

private JTextField areaNameText;

private JPanel panel1;

private JLabel areaRefLabel;

private JTextField areaRefText;

private JPanel buttonBar;

private JButton okButton;

private JButton cancelButton;

}

[7349 byte] By [Ruanaea] at [2007-11-26 15:57:05]
# 1
The code is working fine on my computer using Windows XP.But anyway if you want to set the left margin of a TextField use this:UIManager.put("TextField.margin", new InsetsUIResource(1,4,1,1));
Rodney_McKaya at 2007-7-8 22:17:57 > top of Java-index,Desktop,Core GUI APIs...
# 2
See also this bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4908060
JayDSa at 2007-7-8 22:17:57 > top of Java-index,Desktop,Core GUI APIs...
# 3
Cheers. If it appears to be a bug I'll just tweak the insets as suggested. Thanks for you help :-)
Ruanaea at 2007-7-8 22:17:57 > top of Java-index,Desktop,Core GUI APIs...