简体   繁体   English

在Java Swing中使用null布局

[英]Using null layout in Java Swing

I programmed a game in Java Swing using null layout. 我使用null布局在Java Swing中编写了一个游戏。 Except for a few glitches that I'm working on, it is perfectly functional and looks pretty nice. 除了我正在处理的一些故障,它功能完善,看起来非常好。 My plan: fix the few bugs, add a few extra features, then use SwingWeb or AjaxSwing to allow my game to run in a web browser using HTML/CSS/JavaScript. 我的计划:修复一些错误,添加一些额外的功能,然后使用SwingWebAjaxSwing ,允许我的游戏使用HTML / CSS / JavaScript 在Web浏览器中运行 But after talking to some people here, I feel concerned that my game will not be displayed properly since I didn't use a layout manager. 但在与这里的一些人交谈后,我感到担心我的游戏将无法正常显示,因为我没有使用布局管理器。 Exact placement of components works just perfect for the nature of the game, since I need to have my JLabels moving around constantly, and attempting to this with a layout manager would be very problematic - so I would like to avoid changing from my null layout if I possibly can. 组件的精确放置对于游戏的本质来说是完美的,因为我需要让我的JLabel不断移动,并且使用布局管理器尝试这一点会非常有问题 - 所以我想避免从我的null布局改变我可以。 So before I make a decision about this, can someone explain to me the problems that I could face regarding the null layout if I proceed with my plan as described above? 所以在我做出这个决定之前, 有人可以向我解释一下如果按照上面的描述继续我的计划,我可能会遇到有关空布局的问题吗? Note that clearly I do not intend the window of the game to be resizable, as it will be running in a browser. 请注意,显然我并不打算将游戏窗口调整大小,因为它将在浏览器中运行。

AFAIU null layouts translated to HTML could only result in the position:absolute; 转换为HTML的AFAIU null布局只能产生position:absolute; style. 样式。

That would work even less well in HTML than it would in Swing. 这在HTML中的效果甚至不如Swing。 HTML is supposed to flow, and once the user starts increasing or decreasing the size of the text in their browser, it would fall apart. HTML应该流动,一旦用户开始增加或减少浏览器中文本的大小,它就会崩溃。

Programming with NULL layout is acceptable when you are not resizing you window or you are not using changeListeners, so avoid using the null layout. 如果不调整窗口大小或未使用changeListeners,则可以使用NULL布局进行编程,因此请避免使用null布局。 Read this 读这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM