gpt4 book ai didi

java - TopComponent 调整大小行为

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:52:09 25 4
gpt4 key购买 nike

目前,当您尝试手动调整 TopComponent 的大小时,它会显示一条黑线,表示 TopComponent 的 future 大小。

enter image description here

我想知道这条黑线后面的JComponent是什么?我如何访问它?


编辑

我的问题的第一部分得到了回答。附图中显示的组件是一个JSplitPane

现在,我希望能够访问它(即获取 JSplitPane 的实例,用于在 netbeans 平台中调整 TopComponent 的大小。

最佳答案

  • JSplitPane ,

  • 但不确定 Netbeans 是否是用 Java 编译的(与 Eclipse 相比)

    编辑 我想在上面添加一个监听器。

  • 将 PropertyChangeListener 添加到 JSplitPane,

  • if (propertyName.equals(JSplitPane.XxxXxx))

  • 有一些有用的方法
  • 注意嵌套的 JSplitPane,必须为每个 JSplitPanes 单独添加监听器

  • 例如

.

import java.awt.Dimension;
import java.awt.GridLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;

public class JSplitPaneToy {

public static void main(String[] args) {
JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, makePanel(), makePanel());
JPanel pnl = new JPanel();
pnl.setLayout(new GridLayout(4, 1, 10, 10));
pnl.add(makePanel());
pnl.add(makePanel());
pnl.add(makePanel());
pnl.add(makePanel());
PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {

public void propertyChange(PropertyChangeEvent changeEvent) {
JSplitPane sourceSplitPane = (JSplitPane) changeEvent.getSource();
String propertyName = changeEvent.getPropertyName();
if (propertyName.equals(JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)) {
int current = sourceSplitPane.getDividerLocation();
System.out.println("Current: " + current);
Integer last = (Integer) changeEvent.getNewValue();
System.out.println("Last: " + last);
Integer priorLast = (Integer) changeEvent.getOldValue();
System.out.println("Prior last: " + priorLast);
}else if (propertyName.equals(JSplitPane.RESIZE_WEIGHT_PROPERTY)) {
int current = sourceSplitPane.getDividerLocation();
System.out.println("Current: " + current);
Integer last = (Integer) changeEvent.getNewValue();
System.out.println("Last: " + last);
Integer priorLast = (Integer) changeEvent.getOldValue();
System.out.println("Prior last: " + priorLast);
}
}
};
sp.addPropertyChangeListener(propertyChangeListener);
JFrame frame = new JFrame("JSplitPane Toy");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(0, 2, 10, 10));
frame.add(sp);
frame.add(pnl);
frame.pack();
frame.setVisible(true);
}

private static JScrollPane makePanel() {
JScrollPane pane = new JScrollPane(new JTable(
new Object[][]{{0, 1, 2}, {1, 2, 3}, {2, 3, 4}}, new Object[]{1, 2, 3}));
pane.setPreferredSize(new Dimension(200, 100));
return pane;
}
}

关于java - TopComponent 调整大小行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13135076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com