aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextPane viewable area Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextPane viewable area" Watch "JTextPane viewable area" New topic
Author

JTextPane viewable area

Joe Crew
Ranch Hand

Joined: Apr 02, 2001
Posts: 49
Hi,
I asked this question before but I may have made it too complex a question and may have confused some of you so I'll ask it a little differently.
Here is what I would like to do. Lets say I define a JTextPane to be 10 inches wide and 10 inches in height, but I would only like the viewable area to be only 5x5 inches wide at a time. I want to be able to view the entire JtextPane, but only in 5" by 5" viewable window. When I get to the far right side, or bottom of the viewable window, the window would then move with my next arrow key press. Can someone tell me if this is possible. I've tried some things with scrollbars and a JScrollpane with no luck. I have to have the ability to stop the user when they reach their 10 inch margin and once I introduce scroll bars, there is no way to stop them at 10 inches. This problem comes from the fact that I want to be able to define a Jtextpane to be larger than the screen size someone is limited too, but I still want to limit it to 10 inches. Any ideas at all???
Joe Crew
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

You should be able to yourJTextPane.setMaximumSize(new Deminsion(10, 10)) And so when that point is reached, the user cannot scroll any longer. Set your JScrollPane to be the 5 x 5 prefereed size.
I did something similar with a JPanel and a JScrollPane and it worked.
Hope that helps.
------------------
Happy Coding,
Gregg Bolinger


GenRocket - Experts at Building Test Data
Joe Crew
Ranch Hand

Joined: Apr 02, 2001
Posts: 49
I will give this a try and let you know how it comes out. I've been trying different combinations of things but just not the right combination, mostly trying to move the viewport around.
Thanks,
Joe Crew
Joe Crew
Ranch Hand

Joined: Apr 02, 2001
Posts: 49
Everyone,
I thought I would post this as a guide to anyone else having the same problem. Not shown below is where I created a BorderLayout and my own personal toolbar for text editing commands which I added to the "North" border. Here is the pseudocode for creating a JTextPane that you can create at a size larger than your PC screen size, have scrollbars, and still limit the width of the JTextPane area. The paradox was once I turn on scrollbars I could no longer limit the size of the JTextPane. Note that in main() not shown here I specified the application to have a setSize of 640x480.
<CODE>
private void setScrollBars() {
// These next few variables were actually declared in another
// part of the overall application, I just added them here
// for the sake of clarity. p1 was used for my toolbar,
// thus p2 is shown here.

JPanel p2 = new JPanel();
JTextPane jpane = new JTextPane();
Dimension myDim = new Dimension();

myDim.setSize(1000, 1000);
jpane.setPreferredSize(myDim);
p2.add(jpane);
jscroll = new JScrollPane(p2);
jscroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jscroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
add(jscroll, "Center" );
}
</CODE>
The mistake I made previously, which I am sure could still be fixed by someone, was I added the JTextPane to the JScrollbar, then added the JScrollbar to the JPanel. I could not control the actual size of the JTextPane width or height this way. By adding the JtextPane to the Panel and then adding the panel to the JScrollPane, the panel does all of the scrolling and I can specify the exact size of the JTextPane I want. You also don't have to do any monkey business with moving viewports around this way either.
One issue yet to be addressed by this method is even though you can't see the text beyond the area you create for the JTextPane, text still gets entered past the horizontal limit. I'm working on that issue as I type this, but I wanted to at least post the main solution before this original post got too outdated.
Joe Crew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextPane viewable area