Don't use a GUI builder until you are familiar with the ways to set up a GUI by hand.
The idea behind Swing®/AWT GUIs is that you sue a layout, so the components change size as the whole GUI is resized, to fit different sizes of screen or at the user's instruction. The notion of a component which cannot be resized is inconsistent with the approach. If you insist however, see whether there is a setResizable(boolean) method.
There might be something in the Java™ Tutorials.
Also, you can get the associated Document and add a Document Listener to that. Not sure how you would use that, but there is probably some way to monitor the length of the Document.
Somebody else will doubtless know more than I do.
But with this text pane i should have only place for 4 digits. (number from 1 to 100).
Well you only need room for 3 digits.
Don't use a JTextPane. A JTextPane is used for larger pieces of text.
In gener, for 3 digits use a JTextField:
The text field will then determine its own preferred size. You then use a layout manager that respects the preferred size of the text field.
Then if you want to limit the number of characters the use can type into the text field you can use a DocumentFilter. Read the Swing tutorial on How to Implement a DocumentFilter for a working example.
However, in your case because you only want numbers in the text field you can use a JFormattedText field. This will allow you specify the number of digits to be entered by using a "format mask" and the mask will edit the character as it is typed to make sure it is a digit and not a letter. Read the tutorial on How to Use Formatted Text Fields.
Luke jaryszek wrote:But with this text pane i should have only place for 4 digits. (number from 1 to 100).
There are a couple of issues here, but IMHO the fundamental one is that setBounds() and setSize() simply do not work to set a component's size. That's because the container's LayoutManager that is automatically in place will clobber any size/bounds you might have tried to set. (If you're not using a LayoutManager at all, then those two methods will work, but it is not recommended to not use a LayoutManager except by experts who know what they are doing, and even then only rarely. The rest of this posting assumes that a LayoutManager is in place.)
A method that does work is setPreferredSize(). It's fine if you want to use setPreferredSize(), but Swing's text components generally provide simpler ways of setting size.
JTextPane doesn't, but the only reason to use JTextPane is if you want to handle text in different styles (such as some text in one font and some text in a different font). If you want text in a single style, you could use JTextArea, which has constructors which take rows and columns paramaters: new TextArea(1, 8) Or there are separate setRows() and setColumns() methods. But JTextArea only makes sense if you need to support multiple rows of text.
For a single-row text field you can use JTextField, which has constructors which take a columns parameter: new TextField(4) Or it has a setColumns() method. Or you might want to use a JSpinner instead of a JTextField.
minor footnote: With JTextField you sometimes must to set more columns than you actually need. That's because it sets the required text-width for the whole component, including its borders, but the left and right borders cut into the usable width. This is stupid, but it's been that way for decades and isn't going to change now.