java如何使用JSplitPane组件

java如何使用JSplitPane组件,第1张

package exampleimport javax.swing.*import java.awt.Dimensionpublic class test5 {public static void main(String[] args){JButton b1=new JButton("ok")JButton b2=new JButton("cancel")JSplitPane splitPane=new JSplitPane()//创建一个分割容器类splitPane.setOneTouchExpandable(true)//让分割线显示出箭头splitPane.setContinuousLayout(true)// *** 作箭头山轿,重绘图形splitPane.setPreferredSize(new Dimension (100,200))splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT)//设置分割线方向splitPane.setLeftComponent(b1)splitPane.setRightComponent(b2)splitPane.setDividerSize(1)splitPane.setDividerLocation(50)//设置分卜册割线位于型唯宏中央JFrame frame=new JFrame ("test window ")frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)frame.setVisible(true)frame.setContentPane(splitPane)frame.pack()}}

JPanel actionBar = new JPanel()

actionBar.add(b1)

actionBar.add(b2)

jp1.add(actionBar, BorderLayout.SOUTH)

BorderLayout 是按东西南北中5个位置添加元素厅余肢,你需要它在底部就添加到南部 (SOUTH)。CENTER 部分默认占据毁枯所有剩下的空间。一个位置只扮世能放置一个组件,所以两个按钮需要放进一个 panel 后再把 panel 放到那个位置。

@param newContinuousLayout a boolean, true for the components to redraw continuously as the divider changes position, false to wait until the divider position stops changing to redraw

意思是如果这个参数设置为true,在拖动拆分线期间会不停重绘组件,false时只在棚羡拖动完郑拿成松开鼠标后才进行重绘。你可以将这个参数设为false,然后观察链丛拍拖动时的组件状态(拖动时不要松开鼠标)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11972968.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存