LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-30-2011, 05:00 PM   #1
rmknox
Member
 
Registered: May 2010
Posts: 352

Rep: Reputation: 29
java swing : vertical slider on jtextpane - no thumb


java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.8) (fedora-53.1.9.8.fc14-i386)
OpenJDK Client VM (build 19.0-b09, mixed mode)



I want to add a vertical slider to a JTextPane component.
When I do, I get the slider but I don't get a thumb - i.e. the slider doesnt do anything

here is my code
Code:
    JPanel dataPane   	 = new JPanel();	 		// create panel dataPane
    ta2 = new JTextPane();  						// textpane  

    if (true)
    {
    JScrollPane slider	 = new JScrollPane(ta2);	// slider owns textpane
    slider.setVerticalScrollBarPolicy(				// vertical
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);	// always
    slider.setVisible(true);						// added trying to get it to show correctly
    slider.setEnabled(true);						// ditto
    dataPane.add(slider);							// datapane owns slider									//3    new
    }
    else dataPane.add(ta2);
the (true) lets me do something like ifdef to try out my new ideas

as you see, this code comes when I create the object but before I populate it.
maybe I need to do something after I populate the textpane?

any help would be much appreciated
 
Old 07-31-2011, 04:17 AM   #2
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,217
Blog Entries: 23

Rep: Reputation: 279Reputation: 279Reputation: 279
Okay, for starters, I'd put the textpane in/on a jpanel with a fixed size and put that in a scrollpane.
I think you're confusing this with the known behaviour of a JList where the scroller pops up as soon as the viewport becomes too small to handle the content. A scrollpane is something you use when screen space is at a premium and you nee to show a bit more...

Quote:
JPanel dataPane = new JPanel(); // create panel dataPane
JPanel floater = new JPanel(null); // the floater
ta2 = new JTextPane(); // textpane

if (true)
{
floater.setSize(new Dimension(what,ever));
ta2.setsize(new Dimension(floater.getSize()));
floater.add(ta2);
ta2.setLocation(0,0);

JScrollPane slider = new JScrollPane(floater); // slider owns textpane
slider.setVerticalScrollBarPolicy( // vertical
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); // always
slider.setVisible(true); // added trying to get it to show correctly
slider.setEnabled(true); // ditto
dataPane.add(slider); // datapane owns slider //3 new
}
else dataPane.add(ta2);
I'd try something like that...

Lemme know where this thing lands, okay?

Thor
 
Old 07-31-2011, 01:13 PM   #3
rmknox
Member
 
Registered: May 2010
Posts: 352

Original Poster
Rep: Reputation: 29
Thor

see if I captured your suggestion

result is a tiny bar maybe 1mm high and 1cm long instead of the textpane and slider

when I do it the other way, I get the full pane but with an inoperable slider

when I do it the old way, I get the fell pane and no slider

and YES - I am confused

Dick

Code:
    JPanel dataPane   	= new JPanel();	 		// create panel dataPane
    JPanel floater 		= new JPanel(null); 	// the floater
    JScrollPane slider	= null;
    ta2 = new JTextPane();  						// textpane  
    boolean addSlider = (1<2);						// set to control flow
    boolean thorsWay  = (1>2);						// ditto

    if (addSlider)									// true to add a slider 
    {
    	if (thorsWay)								// do it Thors way
    	{
    		floater.setSize(new Dimension(100,100));		//
    		ta2.setSize(new Dimension(floater.getSize()));	//
    		floater.add(ta2);								// put ta2 in floater
    		ta2.setLocation(0,0);							//
    		slider	 = new JScrollPane(floater);			// slider owns textpane
    	}
    	else slider	 = new JScrollPane(ta2);	// slider owns ta2
    slider.setVerticalScrollBarPolicy(				// vertical
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);	// always
    slider.setVisible(true);						// added trying to get it to show correctly
    slider.setEnabled(true);						// ditto
    dataPane.add(slider);							// datapane owns slider									//3    new

    }
    else dataPane.add(ta2);
 
Old 07-31-2011, 01:35 PM   #4
rmknox
Member
 
Registered: May 2010
Posts: 352

Original Poster
Rep: Reputation: 29
I found what I needed

my original solution was ok, I just needed to add

Code:
    slider.setPreferredSize(new Dimension(330, 500)); // needed this
now when the thumb is needed it appears
 
1 members found this post helpful.
Old 07-31-2011, 01:52 PM   #5
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,217
Blog Entries: 23

Rep: Reputation: 279Reputation: 279Reputation: 279
Cool, glad you found it!

Happy programmin' !

Anything in particular you're working on?

Thor
 
Old 07-31-2011, 08:13 PM   #6
rmknox
Member
 
Registered: May 2010
Posts: 352

Original Poster
Rep: Reputation: 29
for the archive, here is the source that works to put a vertical slider on a JTextPane
Code:
     
    JPanel dataPane   	= new JPanel();	 		// create panel dataPane
    ta2 		= new JTextPane();  	        // textpane  
    JScrollPane slider	= new JScrollPane(ta2);	        // slider owns ta2
    slider.setVerticalScrollBarPolicy(			// vertical
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);	// always
    slider.setPreferredSize(new Dimension(330, 500));   // needed this for it to know when to show thumb
    dataPane.add(slider);				// datapane includes slider
Thor - again, thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Java JTextPane Martin_J Programming 2 02-07-2010 06:05 AM
java swing hangs tERn Programming 2 06-12-2008 07:59 AM
Java swing problem Veteq Programming 4 11-28-2006 03:06 PM
java swing JTextArea gauravbagga Programming 1 05-23-2005 04:34 AM
Java help! Using Swing and Layouts Mega Man X Programming 7 02-05-2004 05:02 PM


All times are GMT -5. The time now is 11:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration