What I want is that the 1st time that the user open my app the left panel can use the full screen!
then I need to resize it.
After reading the SlidingPaneLayout source :SlidingPaneLayout.java, you will find DEFAULT_OVERHANG_SIZE = 32 in this class as the default size of the overhang for a pane in the open state.
Since this is a private static constant,you need to change it into a variable and create its set method.
Take care of onMeasure() method and good luck.
Related
Is there any property or any code that I can implement to make an icon inside a JLabel resizable. Or is there any other item which can store an image, that I could use to have a resizable image inside a JFrame?
use this code :
photo = new ImageIcon(UrlofPhoto);
Image im = photo.getImage();
Image Newim = im.getScaledInstance(yourlabel.getWidth(), yourlabel.getHeight(),Image.SCALE_SMOOTH);
ImageIcon Newphoto=new ImageIcon(Newim);
yourlabel.setIcon(Newphoto);
don't forget to set an initialised size to yourlabel
Generally, I would't suggest trying this with a JLabel as JLabel has a lot of other features you really don't want to messing with (alignment and text).
Generally, a better solution is to use a dedicated "image" panel, which you can provide additional control over to fine tune how you want the scaling to work.
For example
If you're really stuck on using JLabel, I would recommend attaching a ComponentListener to it and resizing the underlying image when ever it changes size. The problem with this is componentResized may be called repeatedly in quick succession, meaning you will need to devise some kind of coalescing algorithm that only reacts to the last event within a given period of time...
Check out Darryl's Stretch Icon which will dynamically scale the icon to fill the label.
I am trying to implement expand functionality like in below example, however instead of a menu I am using a JFrame which contains more sophisticated GUI elements.
The problem I run into is that if I move the parent window which contains the button below which the frame should appear, I can not adjust my custom JFrame to open each time relative to the position of that button
initially I simply used
myCustomFrame.setLocation(myButton.getX(), (myButton.getY() + 73));
but this obviously doesn't work if I change move the parent window
After that I tried
myCustomFrame.setLocationRelativeTo(myButton);
but in this case it appears at the top of the button... I adjust the position for a particular case, but this is not a solution.
So I am trying to get the same behavior as menus have, such that the position of the JFrame is automatically adjusted.
Does anyone have any suggestions?
Have you considered using myButton.getLocationOnScreen()? That way no matter where you move the jFrame containing the button you will always get the Point of your button measured from the top left corner of the screen.
You could alter your original method something like this:
myCustomFrame.setLocation(myButton.getLocationOnScreen().x, (myButton.getLocationOnScreen().y + 73));
I have a TabLayoutPanel and i don't want to give it a fixed height like in the following code example (tabPanel.setHeight("100px");). I want to give it the height of the tab content e.g. the HTML-Widget in the first tab). If i don't set the hight manually, the tab content is not shown at all. Is there any way to get this working with a height adapted to the content?
public class GWTTest implements EntryPoint {
public void onModuleLoad() {
TabLayoutPanel tabPanel = new TabLayoutPanel(3, Unit.EM);
tabPanel.setAnimationDuration(400);
tabPanel.add(new HTML("Tab1 Content"), "Tab 1");
tabPanel.add(new HTML("Tab2 Content"), "Tab 2");
tabPanel.setHeight("100px");
RootPanel.get().add(tabPanel);
}
}
I also tried to mess around directly in the css with the "overflow" and "postition"-attributes, but this then breaks always the animation or something else.
Edit: It seems the easiest way would be to implement my own tab panel - or use an existing javascript library.
Layout panels are a special kind of container in GWT that required sizes from their parents and can size themselves. The basis is the two interfaces ProvidesResize and RequiresResize - indicates that the object will size its children, the other that it must be sized when the parent's size changes. Most layout panels (like TabLayoutPanel) implements both - it needs a size change from its parent, and when it gets it, it will size its children, each tab.
To kick it off though, you need to add the root widget to a RootLayoutPanel, not a RootPanel. There are several chief differences - there is only one RootLayoutPanel (no get(String) method), and the RootLayoutPanel will size its children, while RootPanel will not.
Use RootLayoutPanel.get().add(tabPanel) instead of RootPanel.get().add(tabPanel).
I have also ran up with this issue, but sadly it requires height to be set. All the workaround s where a failure. But some of them suggest the following.
You can try to replace the TabLayoutPanel with a HeaderPanel:
A panel that includes a header (top), footer (bottom), and content
(middle) area. The header and footer areas resize naturally. The
content area is allocated all of the remaining space between the
header and footer area.
Alternatively you can override the onResize() method your ResizeLayoutPanel calculate the height of your embedded content and set the appropriate height.
If you want scrolling functionality you have to embed your VerticalPanel in a ScrollPanel or use CSS to set the oferflow property.
I want to get the present size of my Jframe whenever i click on the button1. This is the code which i have written in my button1clickevent initially when i click on the button i do get a width and height but when i change the size of my Jframe and then again i click on button1 i get the same width and height as i got earlier.The values are not changing anytime.
AppDisplay ap=new AppDisplay(); //class which has got the JFrame
int f12;
f12=ap.getContentPane().getSize().width;
System.out.println(f12+"\n");
f12=ap.getContentPane().getSize().height;
System.out.println(f12);
I think your referencing the wrong Object. What's AppDisplay & why do you need a new instance?
Also, what's wrong with Frame.getSize(); ?
You are printing the size of the Content Pane which is inside the JFrame. Use the JFrame's getSize() method to get the size of the frame.
final Dimension size = ap.getSize();
System.out.println(size);
Also, MadProgrammer makes a good point that the code you show creates a new instance of AppDisplay. You can create as many instances as you want, even without showing them. You will always want to carefully consider the lifecycle of the objects and the scope of the variable names that reference them so that you can refer to the intended object every time.
one idea i found that.
Place a jButton ("jbutton1") one the jFrame.
and write the code inaction performed of the buton.
System.out.println(this.getSize());
then run the frame.
adjust the frame to required size.
then click the button..
we will get the updated size..
then we can set it as the actual size of the frame from properties of jframe...
I am trying to write a slide show program in Java and would like to make the implementation as simple as possible.
The goal is to show a series of slides, each of which has navigation buttons, in addition to other buttons that depend on the slide's content. (A slide showing text would have a magnifyTextButtonand a slide with an image would not have this button.)
I was thinking an abstract Slide class would be appropriate, with subclasses for each slide type: TextSlide and ImageSlide. How would I implement these subclasses so that the magnifyTextButton would show up in TextSlides , and not in any other slide?
Also, my Slide class extends JFrame. Would each instance of a subclass of Slide need to construct a JFrame object if the show is designed to take place in a single window, like in PowerPoint?
How would I implement these subclasses so that the magnifyTextButton
would show up in TextSlides , and not in any other slide?
You can take a flag to decide whether to show magnify button or not. That flag will be true in TextSlides and false in other. Or you can have this button directly in TextSlide and not in other, this way no need to check anything. And processing related to magnify will only go in one class that is TextSlide.
Would each instance of a subclass of Slide need to construct a JFrame
object if the show is designed to take place in a single window, like
in PowerPoint?
In my opinion slide classed should extend JPanel. You can easily change panels on a single frame.
Some questions/answers that can help you in this:
slide effect with JPanel
Slide JPanel Content in a JForm on Java
have look at CardLayout
put Images as Icon / ImageIcon to JLabel
put JLabel contains Image as new Card
You've got a lot going on here, but let's see if I can help out.
1 : I see two options for how to lay out "magnifyTextButton." The first would be to make it a method exclusive to TextSlide. There's no reason that an ImageSlide would need to know anything about magnifyTextButton. In this format, you would then have a "draw" abstract method in your overarching abstract class (which then might be better left as an interface). I don't like this method as much as the one that follows.
Your other option is to make MagnifyTextButton a decorator. This way, you can mix and match MagnifyTextButton onto other classes with text in them (extensions of TextSlide, which you may very well want). This will give you more versatility and will require that your Slide classes need to know even less about MagnifyTextButtons!
2 : I think you want this to be a Jpanel rather than a Jframe.