How to stop size of JTextField from changing when I change font to bold

I'm working on a Sudoku solver for a CS project. I've got JTextFields for the input. I want to bold the entries of the begining puzzle, like they are in the magazines. When I set the font to bold, it changes the size of the text field. I'm using the gridbaglayout and have tried everything to set in stone the size of a text field, but nothing seems to work. I've set the maximum, minimum size, the setSize method, as well as setting the prefered size. But no matter, when I change the font from plain to bold, the box grows in size. How do I prevent this from happening. I can post my gui code if it would help.

Here is a link to my grid, with the upper left square having bold text:

http://12.227.129.113/CS486/Project4/Project4.html

[758 byte] By [oryandunna] at [2007-10-2 18:52:10]
# 1

add them to panel/s set as a gridlayout 9 x 9, or (3 x 3) x (3 x 3)

simple demo of a 9 x 9

import java.awt.*;

import javax.swing.*;

class Testing extends JFrame

{

JTextField[] tf = new JTextField[81];

public Testing()

{

setLocation(200,100);

setDefaultCloseOperation(EXIT_ON_CLOSE);

JPanel p = new JPanel(new GridLayout(9,9,5,5));

for(int x = 0, y = tf.length; x < y; x++)

{

tf[x] = new JTextField(2);

tf[x].setHorizontalAlignment(JTextField.CENTER);

p.add(tf[x]);

}

tf[0].setFont(tf[0].getFont().deriveFont(Font.BOLD));

tf[0].setText("9");

tf[1].setText("3");

tf[66].setFont(tf[66].getFont().deriveFont(Font.BOLD));

tf[66].setText("9");

getContentPane().add(p);

pack();

}

public static void main(String[] args){new Testing().setVisible(true);}

}

Michael_Dunna at 2007-7-13 20:15:00 > top of Java-index,Desktop,Core GUI APIs...
# 2

I had not considered using just the GridLayout. For the sake of argument, is there any way to get the GridBagLayout to listen to me?

Since I'm under a time crunch, I ended up just seting the text field as uneditable, which changed the background color. If I've got a little extra time, I'll go back and rewrite it with a GridLayout and bold those entries.

Thanks for that code sample, it showed me what I needed.

Ryan

oryandunna at 2007-7-13 20:15:00 > top of Java-index,Desktop,Core GUI APIs...