SteSize(w,h) doesn't change displayed sizes

After setSize(w,h) both getWidth() and setHeight() return the proper numbers but visibly on the screen, the dimensions do not change. Code, extracted from the live ap, is compilable.
Using the code below, and clicking "Rotate" button demonstrates this. System.out.println() shows that the sizes have changed internally, but visibly, they do not change. (also nothing shows up at all until the first time "Rotate" is clicked. That, the wrongly clipped border, and the messed up rotation clipping and text placement are separate issues.)
What's wrong here? FWIW: Nearly identical code applied to a JLabel with an image works perfectly. If it works correctly on a JLabel why does it mess up so badly on a JTextPane?
Java is a cool language, but as an old C++ programmer I also find it deeply mysterious (and mystifying) at times.
Thanks in advance for any clues or hints,
--gary
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
public class Rotate extends JPanel  {
    private TextPanel textPane;
    private JLayeredPane parent;
    public Rotate() {
        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
        JToolBar toolBar = buildToolbar();
        add(toolBar);
        parent = new JLayeredPane();
        add(parent);
        parent.setBackground( Color.white);
        parent.setPreferredSize(new Dimension(640, 480));
        // Create a text pane.
        textPane = new TextPanel();
        StyledDocument doc = textPane.getStyledDocument();
        try {
            doc.insertString(doc.getLength(), "This is some sample text.\nIt can be Rotated.", null);
        catch (BadLocationException ble) {
            System.err.println("Couldn't insert initial text into text pane.");
        Border myBorder = BorderFactory.createLineBorder( Color.red );
        textPane.setBorder(myBorder);
        parent.setOpaque(true);
        parent.add(textPane);
        textPane.setDefaultBounds(120, 120, 240, 120);
    private JToolBar buildToolbar() {
        JToolBar toolBar = new JToolBar();
        toolBar.setRollover( true );
        toolBar.setFloatable( false );
        JButton rotateButton = new JButton("Rotate");
        rotateButton.setToolTipText( "Rotate text editing pane" );
        rotateButton.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
                textPane.setRotation(textPane.getRotation()+1);
        toolBar.add( rotateButton );
        return toolBar;
    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);
        //Create and set up the window.
        JFrame frame = new JFrame("Rotate");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        JComponent newContentPane = new Rotate();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
class TextPanel extends JTextPane {
    // implements rotation for a JTextPane
    private int rotation;
    private int tx, ty;
    private int wide, high;
    // valid rotation values are:
    //          0 = no rotation
    //          1 = rotation 90 degree clockwise
    //          2 = rotation 180 degrees
    //          3 = rotation 90 degrees counterclockwise
    TextPanel() {
        rotation = 0;
        tx = 0;
        ty = 0;
    public void setDefaultBounds( int x, int y, int width, int height) {
        high = height;
        wide = width;
        super.setBounds(x,y,width,height);
    public void setRotation( int newRotation ) {
        rotation = newRotation % 4;
        if ((rotation%2)==0) {
            setSize(wide,high);
        } else {
            setSize(high,wide);
        switch (rotation) {
            case 0 : tx = 0; ty = 0; break;
            case 1 : tx = 1; ty = 0; break;
            case 2 : tx = 1; ty = -1; break;
            case 3 : tx = 0; ty = 1; break;
        repaint();
System.out.println("Rotation="+rotation+"  Width="+getWidth()+"  Height="+getHeight());
    public int getRotation() { return rotation; }
    public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        double angle = rotation * Math.PI/2;
        AffineTransform tr = g2.getTransform();
        int h,w;
        if ((rotation%2) == 0) {
            w = wide;
            h = high;
        } else {
            h = wide;
            w = high;
        tr.setToTranslation(h*tx,w*ty);
        tr.rotate(angle);
        g2.setTransform(tr);
        super.paintComponent(g);
}

I spent a few mintues playing with it. I tore up some of the code but I think it works better. It will still need some tweaking:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import javax.swing.text.BadLocationException;
import javax.swing.text.StyledDocument;
public class Rotate2 extends JPanel{
    private TextPanel textPane;
    public Rotate2() {
        JToolBar toolBar = buildToolbar();
        add(toolBar);
        textPane = new TextPanel();
        StyledDocument doc = textPane.getStyledDocument();
        try {
            doc.insertString(doc.getLength(), "This is some sample text.\nIt can be Rotated.", null);
        catch (BadLocationException ble) {
            System.err.println("Couldn't insert initial text into text pane.");
        textPane.setBorder(BorderFactory.createLineBorder( Color.red ));
        add(textPane);
        textPane.setPreferredSize(new Dimension(100, 100));
    private JToolBar buildToolbar() {
        JToolBar toolBar = new JToolBar();
        toolBar.setRollover( true );
        toolBar.setFloatable( false );
        JButton rotateButton = new JButton("Rotate");
        rotateButton.setToolTipText( "Rotate text editing pane" );
        rotateButton.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
                textPane.setRotation(textPane.getRotation()+1);
                revalidate();
        toolBar.add( rotateButton );
        return toolBar;
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
    private static void createAndShowGUI() {
        JFrame frame = new JFrame("Rotate");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        JComponent newContentPane = new Rotate2();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    class TextPanel extends JTextPane {
        // implements rotation for a JTextPane
        private int rotation;
        private int tx, ty;
        // valid rotation values are:
        //          0 = no rotation
        //          1 = rotation 90 degree clockwise
        //          2 = rotation 180 degrees
        //          3 = rotation 90 degrees counterclockwise
        TextPanel() {
            rotation = 0;
            tx = 0;
            ty = 0;
        public void setRotation( int newRotation ) {
            rotation = newRotation % 4;
            switch (rotation) {
                case 0 : tx = 0; ty = 0; break;
                case 1 : tx = -1; ty = 0; break;
                case 2 : tx = -1; ty = -1; break;
                case 3 : tx = 0; ty = -1; break;
            repaint();
        public int getRotation() { return rotation; }
        public void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D) g;
            double angle = rotation * Math.PI/2;
            g2.rotate(angle);
            g2.translate(ty * getWidth(),  tx* getHeight());
            super.paintComponent(g);          
}

Similar Messages

  • I've lost the ability to add new sites, change display size, etc. of sites shown when I open a new tab. What am I doing wrong?

    At some point my ability to add sites from the new tab page, change site displayed sizes, etc. has stopped working. I liked this feature. What changed or what am I doing wrong?

    Do you still see the about:newtab page with the 3x3 tiles?
    Did you modify the number of rows and columns on this page?
    *https://support.mozilla.org/kb/new-tab-page-show-hide-and-customize-top-sites
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem.
    *Switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance
    *Do NOT click the Reset button on the Safe Mode start window
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Change display size of plot area

    I have a VI that is reading signals from 16 different channels. The signals recorded from each of the 16 channels are displayed on 16 different graphs. I want to be able to see all 16 channels at the same time, in case anything interesting happens on any one of them, so each graph is fairly small.(See the attached screenshot.)
    When something interesting does happen, I want to be able easily resize the entire plot area to cover most of the screen--perhaps with the click of a mouse. I would then like to be able to put it back to normal size--perhaps also with a single click of the mouse, or something equivalently as easy.
    Simply zooming in on the "interesting region" will not do.
    Is there a way to easily resize plot areas--b
    y pushing a single button on the keyboard or mouse?
    Attachments:
    labview-screenshot.jpg ‏117 KB

    I would do it like this: Have a main loop that updates the graphs. Have a second loop that has an event structure that looks for button presses. If the user clicks on a graph, the second loop launches a second VI. This VI has its properties set to show front panel when called (File -> VI Properties... -> Windows Appearance -> Customize...) and Close afterwards if originally closed. It front panel basically just your graph and a waveform graph reference (which I hide). It has a loop and an event structure that keeps updating until the graph is clicked. When the graph is clicked, the VI closes. Your original VI needs to keep updating during this and it updates the big graph through a control reference. I have attached an examp
    le.
    Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
    DISTek Integration, Inc. - NI Alliance Member
    mailto:[email protected]
    Attachments:
    aaaBig_Graph.vi ‏32 KB
    aaaSmall_Graphs.vi ‏263 KB

  • Change display size imac

    how do I change the resolution of the screen on a imac?

    Open your Applications folder>System Preferences>Displays>select the "Display" tab>check the "Scaled" box>that will bring up the various Resolution selections.
    Message was edited by: Radiation Mac

  • Replacing audio in QT movie doesn't change overall size of movie?

    H-264 movie made for web distribution. My best video compressor only creates AIF audio files ... which are mighty big.
    I made an MP3 audio file in Logic.
    I replaced the original AIF audio in the Quicktime movie with the MP3 audio ... (which is 23 megs smaller) but 'info' says the QT movie is still the same size.
    How can I replace audio track in QT movie (with a smaller size audio track ... and see the difference registered in the QT movie 'info'?
    All ears,
    Ben

    Open your audio/video QuickTime file and then open the the Movie Properties window.
    Highlight (single click) on the "Video" track and "Extract" (upper left of that window) to make a new video only version.
    Open your audio QuickTime file, select all (Command-A) and copy (Command-C). This stores your audio track on the Clipboard.
    Switch back to your "extracted" video track, select all (Command-A) and choose "Add to Selection & Scale" (Edit menu).
    Test this file and then "Save As" to make a self contained QuickTime .mov file from these parts.

  • How do I change display size

    I have to scroll horizontally to see a full screen.  Is there a setting to fix this problem?  Also, any way to resize the display in Chrome? In Windows, I can grab the edge of the page and drag it to fill the screen. 

    System Preferences>Displays>Display Tab>Scaled Button and choose another resolution. The one at the top of the list is the 'recommended' setting.

  • Changing display size on "Compose Email Page" in Outlook

    I am faced with a weird problem that has made my life miserable while using my Lenovo T430 machine. On the compose email page in outlook I must have hit some key combo coupled with some action on the trackpad and the fonts in the compose email became soooo small that I needed a magnifying glass to see them.
    Can someone please help me restore the settings to normal. I would be truly grateful.

    In addition to the above is there a list of shortcut key combos that work with the trackpad in this particular model? I would idebted for life is someone can help me out here.

  • Changing resolution and image size doesn't change result on screen?

    I'm using Photoshop CS3. I am trying to change the resolution of several images that will be printed in a newspaper. So the current images are 72 ppi and really huge -- for example 36 x 27 inches (document size), and when I change them to 300 ppi, the image sizes shrink to about 8 x 6 inches, as I expect. But the image I see on the screen doesn't change. So, for example, when I open up the image originally, it's at 33% and the entire image is visible. After I change the resolution, and the image size has changed accordingly, the image still appears the same and it remains at 33%. Shouldn't the image shrink on the screen since its size has shrunk? Or if it remains the same on the screen, shouldn't the percentage shift? I mean if the document size is now 8 x 6, it should be able to be displayed at 100% and not fill my whole screen... I'm so confused. Thanks...

    gradded,
    The "Document Size" area of the Image Size dialog is just to indicate the size (in inches) that your document will be printed. The ppi adjustment has nothing to do with what is displayed on your monitor. Your monitor doesn't care anything about ppi. The monitor contains a certain number of pixels and after you change that ppi setting, the monitor will still have that same number of pixels.
    As long as you leave the "Resample Image" box unchecked, your image size (Pixel Dimensions) will not change. You will see no change on your monitor. If you check the "Resample Image" box, then your image size (in pixels) will change.
    Hope this helps.

  • The html container doesn't change size according to the width of the website, but instead the width of the window.

    As stated. The html container doesn't change to match the content on the website (like Internet Explorer does), it changes to match the screen size. That way, when you scroll horizontally, elements disappear because the html container is the size of the screen and in a fixed position.
    Example (my problem): http://www.elitepvpers.com/forum/web-development/1847846-question-css-html-width-problem.html
    Happens with most websites such as...
    http://google.com/
    http://co.91.com/index/
    http://www.w3schools.com/
    http://stackoverflow.com

    locked by moderator as dulicate

  • Some of the album artwork on my iPod is wrong. I've tried to change it many times but it doesn't change. I've decided that the easiest thing to do now would be to NOT display album artwork on my iPod. How do I set my iPod to NOT display album art?

    Some of the album artwork on my iPod is wrong. I've tried to change it many times but it doesn't change. I've decided that the easiest thing to do now would be to NOT display album artwork on my iPod. How do I set my iPod to NOT display album art? I've checked the User manual and that doesn't help.

    Why don't you, instead of taking time to do that, just backup, and then restore your iPod?
    Just a suggestion..

  • I used to have a +.- displayed in upper left corner to click and change text size. My sister used my computer and now I can no longer find this feature.

    I used to have a +.- displayed in upper left corner to click and change text size. My sister used my computer and now I can no longer find this feature

    Do you still have all toolbars visible (View > Toolbars)?
    Did you use an extension or the standard zoom buttons that you can find in the toolbar palette in the View > Toolbars > Customize window ?
    Press F10 or tap the Alt key to bring up the "Menu Bar" temporarily.

  • How to change the size of the characters displayed on GUI screen?

    Hi All,
    My problem is : the characters displayed on GUI screen are smaller than other associates when we are in same condition.
    Can anyone tell me what i should do to change the size?
    Thank you very much.
    Regards,
    Fiona

    hi,
    click on the layout menu button at the end of standard tool bar.
    select visual settings. there u will get font size options.
    u can manage through this your font size.
    and this will effective with the first front end mode u start.
    layout menu button >> visual settings >>general tab>> font size
    hope it will help you.
    Edited by: Sachin Gupta on Jul 15, 2008 9:42 AM

  • Using my macbook alternately with cinema display and without makes all my screens shift and change in size ?!

    After I disconnect from the cinema display and than a few minutes later open up the macbook without the display connected, things are fine. But re-connecting to the display, all the screens are moved and/or changed in size. Anybody any ideas ?

    I'm currently sitting in my office using my MBP and looking at a 24" Samsung display. At home I replaced my 4 year old iMac with a 2 year old 13" MBP which is connected to a similar display. That should be tell you all you need to know! 

  • How do I change the size of display on my desktop?

    How do I change the size of display on my desktop?

    Where the apple sign  and than safsir  file  view history bookmards window help etc to make smaller

  • Change image size in web display of SRM MDM 3.0

    Hello,
    how can I change the size of the displayed images in the catalog?
    I would like to display the image in the detail of the material data in the catalog larger.
    The images are stored in in the repository.
    Thanks for your help.
    melanie

    You can change this in the Web UI interface. In the Customize Display tab you can specify the size of you images to be displayed in pixel.
    The UI interface that I'm talking about is where you change your OCI mapping, Search... etc
    If you want to crop, resize your uploaded images you can do this in MDM Data manager.
    Edited by: Joy Natividad on Mar 3, 2010 7:08 PM

Maybe you are looking for

  • Re: Raising Exceptions Vs returning erro[Ref:C809787]

    Hi Steve ! Probably the following explanation might help in resolving the issue raised by you: At a more abstract level, there is only one thing, i.e. the EVENT. According to it's definition, an event is a relatively infrequent occurrence in one port

  • How do I downgrade to iTunes 11.4?

    So, I made the mistake of updating to iOS 8 the other day, and when I went to sync my iPhone today, discovered that iTunes 11.1.3 (Mountain Lion, 10.8.5) won't let me sync my music because I'm running iOS 8.  I DO NOT LIKE ITUNES 12.  It's a visual n

  • Ipod in recovery mode

    Hi, my ipod is out of warranty and was working for almost 2 yrs now. I have been experiencing this problem from last two days but not able to find any fix yet. i have tried this article almost three time http://docs.info.apple.com/article.html?artnum

  • Transparency flattening - unwanted color added to transparent PSD files (IDCS3)

    Recently (after switching to CS3) I began experiencing frustrating problems in relation to (what I think is the problem) transparency flattening. The problem seems to evolve in the printing process where "something" messes up the transparency by addi

  • How do i change amplitude names

    I have 2 amplitudes for the graph. I could change only 1 amplitude name using property node from program? how do i change name for second one from program? Thank you, Ranjith