How can I have a jfreechart ChartPanel automatically enlarge itself? - swing

I have a Swing JFrame with a ChartPanel as its only component. When I resize the frame, the chart panel gets stretched out as if it were an image. For example, if I shrink it vertically, all of the character get compressed.
Is it possible to have the ChartPanel redraw itself on resize events so that it shows more detail on the graph, instead of getting stretched as a static image?

You have to change a few options when constructing your ChartPanel :
* #param minimumDrawWidth the minimum drawing width.
* #param minimumDrawHeight the minimum drawing height.
* #param maximumDrawWidth the maximum drawing width.
* #param maximumDrawHeight the maximum drawing height.

I had the same issue. I now realize that ADR gave the solution: you have to set the minimum and maximum drawing width and height, for example:
chartPanel.setMinimumDrawWidth( 0 );
chartPanel.setMinimumDrawHeight( 0 );
chartPanel.setMaximumDrawWidth( 1920 );
chartPanel.setMaximumDrawHeight( 1200 );

ChartPanel has methods to control zoom, as shown in this example. I don't see characters getting compressed.

Related

Scaling inside the clip

How to scale inside a clip?
I dynamically create a clip that simulates a window and calculate its width as
stage.stageWidth * my_window_width / my_scene_width;
inside the window, i need to create a square that must have a width, coordinate x, and so on, proportionally scaling according to the size of the window screen. Because if the size of the square is set pixel by pixel, then the sizes differ on different screens.
You could setting square w/h according to window size...
mc_window.square.width = (mc_window.width / 8); //square is eight times smaller
mc_window.square.height = mc_window.square.width; //set to "square" geometry
I create a clip that simulates a window:
window_bonus = new windowBonus;
window_bonus.x = stage.stageWidth * indent_to_x_to_photoshop / width_all_file_photoshop;
window_bonus.y = stage.stageHeight * indent_to_y_to_photoshop / height_all_file_photoshop;
window_bonus.width = stage.stageWidth * width_of_photoshop / width_of_all_file_photoshop;
window_bonus.height = stage.stageHeight * height_of_photoshop / height_all_file_photoshop;
I get a window like in figure 1.
Then I create another clip on the window - figure 2.
And on the device it looks like in figure 3.
I decided to create clips of containers that are not initially visible but they are installed on the window and therefore are scaled with the window,
Inside them already, I load the card image.
But my question is how to scale without containers,
using width, height, x and y
for a nested clip?

Increase an Image's clickable area

Edit: I am using LibGDX framework.
There is an Image Actor, which is:
Attached to a Stage.
Has an OnClickListener, e.g.:image.addListener(new OnClickListener() { ... });
This Image's touchable area is fixed on the image's width and height.
I want to increase the touchable area by N pixels.
How can I achieve this?
Here's an illustration:
(red rectangle = touchable/clickable area)
Image already supports this out of the box. The actor can be bigger than the drawn image itself. You can supply a Scaling strategy for the drawn picture and in case you use Scaling.none, the drawn picture will be independent of the actor's size.
image.setScaling(Scaling.none)
int N = 30;
image.setSize(image.getImageWidth() + N, image.getImageHeight() + N);
The way I would approach it, is to have a custom image view, with the actual Image View inside a RelativeLayout. The relative layout has padding and/or margin set, so that it is bigger than the imageView. then, when you set the onClicklistener, set it on the relative layout as well as the image layout (in your custom class)

how to get the global width and height of movieClip after scaling parent(s)?

I do work on some already developped project.
myMovieClip has been scaled and is nested into many movieclips which may have been scaled themselves
When I trace his width and height, it does not give me the right width and size:
How can I get the absolute width and height ?
(the width and height it takes on the screen)
(a kind of localToGlobalWidth function)
regards
You can use the getBounds method of a display object to get the bounds (actual width/height and position) relative to whatever display object you pass to the method as an argument. (doucmentation)
myScaledObj.getBounds(stage); //would return a rectangle of where on the stage the display object is.
The width and height property of the returned rectangle would be what you'd use.
Do you know how many times it's been scaled, and by how much it's being scaled? In that case, you could trace the width * the scaling, for example:
mc1 has a width of 100, and is being scaled by 2:
mc1.scaleX = 2;
trace (mc1.width*2);
Extra information: if it's being scaled by a variable, replace 2 with the variable name.
This method should work even if it's being scaled multiple times, by using a variable to pile up the scaling:
var scaler1:int = 2;
var scaler2:int = 7;
var scalePiler:int = scaler1*scaler2;
mc1.scaleX = scalePiler;
trace (mc1.width*scalePiler);
Hope I helped and covered all possibilities, good luck with your program! ^^

Change div size to scale when window resized

Basically, I have a div that contains my entire website. it has a height of 625px and a width of 1250px. Is there any way to resize this while keeping the scale when the browser window is resized or its used on a mobile/tablet? I know someones gonna say use % instead of px but I have a very controlled UI.
Also is there anyway to bring up a pop up when the websites used in a certain browser?
Thanks
The best and most straightforward answer is to use %, simply because this is the intended use. I'd really advise you to rework your layout so the percentage sign can be used.
If this does not work for you, there is always Media Queries http://www.w3.org/TR/css3-mediaqueries/ or Javascript as pointed out by #sable-foste and #abdul-malik.
For whatever reason you are doing it you can use this (using JQuery):
$(window).resize(function() {
resizeSite();
});
function resizeSite(){
var winH = $(window).height();
var winW = $(window).width();
// you will want to do some stuff here for deciding what to do and when...
// when the window size is too small shrink the site using your ratio
// when the window is larger increase the size of your site i.e.
// Height = Width / 2
// Width = Height * 2
var tgtW = winH * ratio;
var tgtW = winH * ratio;
$("#siteContainer").height(tgtH).width(tgtW);
}
And add a call to the function on load as well. I think doing this would probably create you even more issues though as this would just shrink the size of the containing element, what happens to the content of it? If it was scaled down to fit on a mobile phone in portrait the display would be tiny and pointless, what would the layout inside it be?

resizing widget in pygtk

I have a scrolled window, which contains a drawing area in pygtk. I would like to change the size of the drawing area, and keep the scrolled window as it is. I don't find a function that works on widgets. I can get the size and so on, but I can't set it. Could someone give me a pointer to the solution?
Thanks,
v923z
It sounds like .set_size_request() is what you need. An example would be:
drawingarea.set_size_request(400, 400)
The values are the width and height of the canvas. Assuming you're ScrolledWindow is setup correctly, the scrollbars should adjust automatically to the size of the DrawingArea.