English 中文(简体)
Java Layout Problems
原标题:Java Layout Problems
  • 时间:2012-01-14 13:30:38
  •  标签:
  • java
  • swing

在一项地雷项目中,我一直试图在JPanel witch上增加一名JConsonle,由另一个JPanel控制。

问题是,JConsole从JPanel上排5px。 在I tought, 它是固定床位的集装箱,但在给它留下了红色的背景之后,我认识到,ole正在从顶头上 set5px。

I ve also tried to use BorderLayout to set it in the NORTH or CENTER of the JPanel but that dosent work either.

这是我的法典:

public class MonopolyPanel extends JPanel {

  JPanel consoleP = new JPanel();
  JConsole console = new JConsole();

  MonopolyPanel(){

   this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
   console.setPreferredSize(new Dimension(530, 300));  
   consoleP.add(console);
   this.add(consoleP);

  }
}
最佳回答

青少年被添加到青春期。 缺省有流动资金,缺省有5px的纵向和横向差距。 证实如果出现零缺口的流放,那么trick就应当

consoleP == new JPanel(new FlowLayout(align, 0, 0));
问题回答

From my experience, the best and most flexible layout is GridBagLayout.

在Swaing I的99%的小组都是GridBagLayout,否则就不可能得到所有的权利。

由于这种布局,你可以确定重量、确切的间隔和间隔参数。

其他布局器是有限的,不能令人信服。

查阅<代码> 边界?

您可能有必要制定<代码>。 JPanel s or the JConsole s Border to an EmptyBorder, such as:

component.setBorder(BorderFactory.createEmptyBorder());

You might also look for something about insets in the Javadocs.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签