有趣的問題(我不是太有尋找到JPA我應該熱情)
基本上,它是沒有太大的佈局可能對自己做的事:ScrollPane的PREF大小的不同而不同的能見度水平滾動條。這需要客戶端代碼來動態地告訴管理人員如何處理待處理區域IMO。下面是一個代碼片段。
- 它使用與也許可見水平滾動條(是的,女同胞們,我知道,那固定的大小應動態調整,以任何高度變化滾動窗格的水平滾動條屬性的固定大小的隱形啞分量:-)
- 它在scrollPane的水平滾動條上安裝componentListener,根據可見性更改調整假人的隱藏模式並重新驗證包含面板。爲Win /雨雲
工作正常,有一個在金屬毛刺,雖然(也許其他的LAF),這需要一個幻數調整差異,以保持佈局穩定
JTextArea area = new JTextArea("starting ", 1, 10);
JScrollPane areaScrollPane = new JScrollPane(area);
areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
areaScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
Dimension dim = areaScrollPane.getPreferredSize();
areaScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// get the height diff with/out horizontal scrollbar
int diff = dim.height - areaScrollPane.getPreferredSize().height;
areaScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
LC lc = new LC().wrapAfter(2).debug(500);
final MigLayout layout = new MigLayout(lc);
final JPanel panel = new JPanel(layout);
panel.add(new JLabel("OneLineRow"));
panel.add(areaScrollPane);
// create and add an invisible filler
// note: metal needs magic adjust, dont know why
// diff -= 3;
final JComponent dummy = (JComponent) Box.createVerticalStrut(diff);
dummy.setVisible(false);
final String dummyConstraint = "span, hidemode ";
panel.add(dummy, dummyConstraint + "0");
// component listener which adjusts hidemode of filler on
// scrollpane's horizontal scrollbar showing/hiding
ComponentAdapter adapter = new ComponentAdapter() {
/**
* @inherited <p>
*/
@Override
public void componentShown(ComponentEvent e) {
layout.setComponentConstraints(dummy, dummyConstraint + "2");
panel.revalidate();
}
/**
* @inherited <p>
*/
@Override
public void componentHidden(ComponentEvent e) {
layout.setComponentConstraints(dummy, dummyConstraint + "0");
panel.revalidate();
}
};
areaScrollPane.getHorizontalScrollBar().addComponentListener(adapter);
panel.add(new JScrollPane(new JTable(20, 5)), "span");
showInFrame(panel, "one line textArea");
反饋非常歡迎,也許我忽略了一個不太人爲的方法