473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using Canvas within JSplitPane

Hi all,

I was referring to
http://forum.java.sun.com/thread.jsp...&thread=204595
to handle the resizing problem.

So I put the canvas into a JScrollPane, and then add the pane into the
JSplitPane.
The code is as follows:

JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
final Canvas canvas = new Canvas();
final JScrollPane scrollPane = new JScrollPane(
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JPanel panel = new JPanel();

//scrollPane.getViewport().setLayout(new BorderLayout());
scrollPane.getViewport().add(canvas);

splitPane.add(panel);
splitPane.add(scrollPane);

PropertyChangeListener pcListener =
new PropertyChangeListener()
{
public void propertyChange(PropertyChangeEvent pcEvent)
{

scrollPane.getViewport().setSize(splitPane.getRigh tComponent().getSize());
canvas.setSize(splitPane.getRightComponent().getSi ze());
}
};

splitPane.addPropertyChangeListener(pcListener);

The problem is that the canvas won't resize. Is that the lines in
propertyChange() method is not correct? If this is the case, how should I
correct that?

Also, if I uncomment the line
//scrollPane.getViewport().setLayout(new BorderLayout());
the divider of the split pane could not be slided towards the canvas' side.
Is this the nomral behavior, just because I'm mixing heavy and light weight
components together?

Thanks!

Regards,
Dominic
Jul 17 '05 #1
1 6776
Thanks!

"Anders Zellén" <an***********@home.se> wrote in message
news:8h*******************@newsb.telia.net...
According to suns documentation
(http://java.sun.com/docs/books/tutor...ing/table.html) you should use a subclass of a JPanel instead of a Canvas when you are using
Swing.

You just make a subclass of a JPanel and overwrite the paintComponent method for drawing
Anders Zellén

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gordon Airporte | last post by:
I'm trying to get my canvas to resize to fill its frame within a window, but I can't figure out how to handle the callback data from the window's <Configure> properly. It has very strange behavior...
4
by: Clinton Pierce | last post by:
In Tk and other graphical toolkits, there's a "Canvas" widget that allows you to draw figures and place text on it at runtime. Later these "shape objects" can be clicked on (they have their own...
0
by: mhodkin | last post by:
What is the best way to print a graphic image contained within the canvas oject in Tkinter ruinng under Windows (XP)? The only thing I found so far was the canvas postscript method...it there a...
0
by: WaterWalk | last post by:
Hello. When I tried to make Tkinter canvas widget respond to MouseWheel event on Windows XP, I failed. The canvas just doesn't receive MouseWheel event. I used bind_all to find out which widget...
0
by: aaronwmail-usenet | last post by:
Announcing SkimpyGimpy Support for PNG image CAPTCHA generation and PNG canvases. You can now use SkimpyGimpy to generate CAPTCHA text representations as PNG image files in addition to...
2
TMS
by: TMS | last post by:
Schools over!!! Now its time to play. I would like to learn how to make objects move from one location to the next on a canvas widget. For example: from Tkinter import * class square:...
4
by: crazychrisy54 | last post by:
Hi there, I am new to JavaScript and wonder if it could be used to solve my problem, any help would be much appreciated! I have a html web page which contains a table on the left hand side and...
8
by: moondaddy | last post by:
I'm posting code for a user control ( FunctionConnectorSelector) below which has 3 content controls in it. each content control uses a style from a resource dictionary merged into the app.xaml...
4
by: moondaddy | last post by:
I have a wpf project where I use a canvas to drag shapes around. when I drag a shape beyond the right or bottom side I get scrollbars which is good. I also get scrollbars when I zoom in and a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.