GridLayout上的JButton-MineSweeper [英] JButtons on GridLayout - MineSweeper

查看:110
本文介绍了GridLayout上的JButton-MineSweeper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写MineSweeper,并在GridLayout上使用JButton.用户输入的行数和列数,因此设置固定大小可能会引起一些问题.

I'm writing MineSweeper and using JButtons on a GridLayout. The numbers of rows and columns are entered by the user, so setting fixed size may cause several problems.

如何在不设置面板固定尺寸的情况下删除按钮之间的空间?

How can I remove the space between the buttons without setting the fixed size of the panel?

推荐答案

使用JButton然后使用GridLayout

在这里,我将JButton替换为JPanel(还有一些边界魔术)

Here, I replaced JButton with JPanel (and some border magic)

我尝试的另一件事是将负h/vgap传递给GridLayout

The other thing I tried was passing a negative h/vgap to the GridLayout

但是,我不建议这样做,因为它可能会对其他平台产生无法预料的影响.

I'd however not recommend this, as it may have unforeseen effects on other platforms.

我个人很想使用自定义的JLabel(附带自己的鼠标侦听器)代替按钮.单击它甚至可以触发事件和动作事件.

I personally, would be tempted to use a custom JLabel (with it's own mouse listener attached) to take the place of the buttons. You could even fire and action event when it's clicked...

这篇关于GridLayout上的JButton-MineSweeper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆