简体   繁体   English

使JFrame的左上角(0,0)

[英]Make the top left of a JFrame (0,0)

我正在JFrame中进行平铺,我只是认为如果地图的左上角是(0,0)会更容易处理,因为它可以更轻松地通过2d数组解释位置。

I'm doing some tiling in a JFrame 我正在JFrame中进行平铺

You should NOT be doing tiling in the frame. 您不应该在框架中进行平铺。

Instead you add a JPanel to the frame and do the tiling in the panel. 而是将JPanel添加到框架并在面板中进行平铺。 Then the top/left of the panel will be(0, 0). 那么面板的顶部/左侧将是(0,0)。

Read the section from the Swing tutorial . 阅读Swing教程中的部分。 There are topics on: 有以下主题:

  1. Custom painting - if you are painting your own tiles. Custom painting -如果您要绘画自己的瓷砖。 The tutorial shows how to do custom painting on the panel 本教程显示如何在面板上进行自定义绘画

  2. How to use GridLayout - if you want to add real components to the panel. How to use GridLayout如果要将真实组件添加到面板中。

In either case the frame is just a container for the panel. 无论哪种情况,框架都只是面板的容器。 All the code/logic belongs in the panel. 所有代码/逻辑都属于面板。

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

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