2012-06-09 70 views
4

我有保证金问题。可能它很容易解决,但我不知道是什么原因。我有四个组件,三个jscrollpanel和一个jpanel。元件放置这样的:Java + Miglayout - 上边距边框问题?

components

问题是用红色标出椭圆。如何擦除这个边缘?我知道,这个问题与边界有关(甚至是为每个组件创建相同方法的边界)。进出口使用此:

setBorder(BorderFactory.createTitledBorder("Sterowanie:")); 

但是,当我不设置JPanel的(与标签“Sterowanie”组件)的边界,它填补所有的地方了无空白。有了边界,它只是填满了一个有边界的区域。我用来放置组件的代码:

proxys = new ItemViewer("Numery:"); 
add(proxys, "height 65%, width 33%"); 

accs = new ItemViewer("Konta:"); 
add(accs, "height 65%, width 33%"); 

panel = new JPanel(); 
panelLayout = new MigLayout("insets 0 0 0 0"); 
panel.setBorder(BorderFactory.createTitledBorder("Sterowanie:")); 
add(panel, "height 65%, width 34%, wrap"); 

log = new Log("Log:"); 
add(log, "height 35%, width 100%, span"); 

嗯?

+0

“MigLayout”没有太多的经验,但是您尝试过使用[CompoundBorder](http://docs.oracle.com/javase/7/docs/api/javax/swing/border/ CompoundBorder.html),但是当你尝试将它与'TitledBorder'一起使用时,只需添加一个'EmptyBorder',希望这可以在某种程度上有所帮助:-) –

回答

1

不知道为什么会发生这种情况(我的第一个猜测是ItemView与普通面板的垂直默认对齐方式不同),但可以通过在单元格或行限制中使所有单元可增长来重现和变通方法:

JComponent comp = new JScrollPane(new JTable(20, 1)); 
    comp.setBorder(new TitledBorder("Some Item")); 
    JComponent other = new JScrollPane(new JTable(10, 1)); 
    other.setBorder(new TitledBorder("Other items")); 
    JComponent panel = new JPanel(); 
    panel.setBorder(new TitledBorder("Stewhatever")); 
    JTextArea log = new JTextArea(); 
    log.setBorder(new TitledBorder("Log")); 

    MigLayout layout = new MigLayout("wrap 3, debug"); //, "", "[fill, grow]"); 
    JComponent content = new JPanel(layout); 
    String cc = "width 33%, height 65%, grow"; 
    content.add(comp, cc); 
    content.add(other, cc); 
    content.add(panel, cc); 
    content.add(log, "height 35%, span, grow"); 

没有任何增长,片段再现你的截图,用生长在任一毫升或注释行的约束,所有的上部件在顶部对齐。

不知道这是bug还是应该预计​​

+0

+1对于任何 – Rekin

2

您使用MigLayout对我来说(无意冒犯,请,我只是学会了另一种方式)有点不可思议的方式。试试这个:

content.setLayout(new MigLayout("fill", "[sg, grow][sg, grow][sg, grow]", "[65%][35%]")); 
content.add(topLeftComponent, "grow"); 
content.add(topMiddleComponent, "grow"); 
content.add(topRightComponent, "grow, wrap"); 
content.add(bottomComponent, "span 3, grow"); 

我知道这是不一样的“精神”,但我总是发现这种风格更容易建立。

+1

当然没有任何问题:)我忘记标记为已解决的问题,我在一年前使用过kleopatra解决方案。但是你的回答也很有用,也许有人会有同样的问题,然后他可以尝试这两种解决方案。谢谢! – marxin