2012-06-09 68 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