Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
Why my JSplitPane can't hide or show as I want?
Qunfeng Wang
Ranch Hand
Posts: 434
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import javax.swing.*; import java.awt.event.*; import java.awt.event.ActionEvent; import java.awt.BorderLayout; import java.awt.Dimension; public class SplitPaneTest implements ActionListener{ boolean show = false; JButton buttonB = new JButton("Show or Hide"); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); public SplitPaneTest() { JFrame frame = new JFrame("SplitPane show and hide test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultLookAndFeelDecorated(true); frame.setSize(500, 400); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); JButton button = new JButton("OK"); button.addActionListener(this); splitPane.add(button, JSplitPane.TOP); splitPane.add(buttonB, JSplitPane.BOTTOM); // splitPane.setResizeWeight(0.3); hide(); frame.getContentPane().add(splitPane, BorderLayout.CENTER); frame.setVisible(true); } public void actionPerformed(ActionEvent actionEvent) { if(show) { hide(); show = false; } else { show(); show = true; } } public void hide() { splitPane.setDividerLocation(1000); buttonB.setVisible(false); } public void show() { splitPane.setDividerLocation(20); buttonB.setVisible(true); } public static void main(String[] args) { new SplitPaneTest(); } }
It's quite strange, I need to click the "split line" to show the "buttonB". Is my implemention wrong? Or just have some tricks in int?
Thank you.
To be or not to be. It's a question.
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
URGENT PLEASE
NullPointerException
Problem with JTree inside JScrollPane inside JPanel
JSplitPane resizing
JSplitPane with JScrollPane
More...