我正在尝试将JscrollPane添加到我的JTextPane中,当我运行它时它不会显示。我搜索了互联网,大多数答案都没有帮助。
这是我在我的代码中实现它的方式
JTextPane t = new JTextPane();
JScrollPane s = new JScrollPane(t);
s.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
t.setBounds(10,50,60,70);
s.setBounds(10,50,60,70);
Pane.add(t);
Pane.add(s);
答案 0 :(得分:3)
首先摆脱override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.optimizeForSize(self.view.bounds.size)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
//calculate frame for the box container based on current frame
//...
boxContainer.updateLayout()
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
coordinator.animateAlongsideTransition({ (conext: UIViewControllerTransitionCoordinatorContext) -> Void in
self.optimizeForSize(size)
self.view.setNeedsLayout() //needed for iOS 8
}, completion: nil)
}
func optimizeForSize(size: CGSize) {
if size.width > size.height {
self.boxContainer.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI / 2.0))
} else {
self.colorPicker.transform = CGAffineTransformIdentity
}
}
和t.setBounds(10,50,60,70);
以及s.setBounds(10,50,60,70);
。组件只能驻留在单个容器中,通过调用Pane.add(t);
从组件的父容器中移除组件(Pane.add(t)
)。
另外,请确保您使用适当的布局管理器来管理布局(无需拨打JScrollPane
)
您可能还希望阅读Code Conventions for the Java TM Programming Language,这样可以让人们更轻松地阅读您的代码并让您阅读其他代码