Drawing a gridline in the same part where I created the JPanel?

后端 未结 2 952
广开言路
广开言路 2021-01-15 11:43

I need to build a gridline for a crossword puzzle. I wanted to know if I could do it in the same part where I created the JPanel and it\'s properties instead of doing it in

2条回答
  •  伪装坚强ぢ
    2021-01-15 12:01

    First off, never do this: setLayout(null);. While null layouts and setBounds() might seem to Swing newbies like the easiest and best way to create complex GUI's, the more Swing GUI'S you create the more serious difficulties you will run into when using them. They won't resize your components when the GUI resizes, they are a royal witch to enhance or maintain, they fail completely when placed in scrollpanes, they look gawd-awful when viewed on all platforms or screen resolutions that are different from the original one.

    But more to your original point, my suggestion is not to draw gridlines. Instead consider using a JPanel that holds a GridLayout, you can give it a horizontal and vertical gap of 1, and set is background to black if you want to show gridlines, and then fill it with either JLabels or JTextFields that accept one single char.

提交回复
热议问题