Switching panels in AWT

Hi, having a problem with switching 2 panels within a frame. Am using the following code within the frame file:
removeAll();
recPlay = new RecPlayPanel(tvacs);
recPlay.start();
add(recPlay);
this.repaint();
When this code is exectuted the first panel is removed but the second is not displayed, yet if you resize the frame it suddenly appears. Does anybody know why this happens. NOTE: this must be done using AWT components only as is to run on JEODE runtime. Thanks in advance, Alan

You should probably call validate() since that'll set the size of the panel according to your layout policy.
Hope this helps.

Similar Messages

  • Switch panel lights on all the time after keyboard replacement

    I replaced the keyboard on my DV6000, now the keyboard works fine....but the blue lights on the switch panel are on all the time whether the machine is powered up or not.  I re-connected everything per the service manual instructions, and have now triple checked my work....help!
    Just as an FYI, I have 2 DV6000's, and just today replaced the trackpad on the other one, and now have the same issue with that one!!!!!
    What gives?
    Thanks in advance for the assistance.
    John

    Seriously?  No one has experienced this issue?
    Anyone from HP out there care to help me out?

  • Panels in AWT

    Can't we use Panels in awt...
    AWTTest(){
              BorderLayout bord=new BorderLayout();
              setLayout(bord);
              setBounds(40,40,600,400);
              Panel p=new Panel();
              p.setLayout(null);
                        Button btn1=new Button("OK");
                        btn1.setBounds(10,10,60,20);
                        p.add(btn1);
              Panel p1=new Panel();
              p1.setLayout(null);
                        Button btn2=new Button("OK");
                        btn2.setBounds(10,10,60,20);
                        p1.add(btn2);
              add("Center",p);
              add("South",p1);
    setVisible(true);
    Since it only apperas "Center"
    Where is the South

    you're using an obsolete version of add() when you add the Panels to the outer container, and the constants "Center" and "South" may be obsolete or meaningless to BorderLayout as well. Use BorderLayout.CENTER and BorderLayout.SOUTH.
    Also, when you post code, wrap it in [code][/code] tags.

  • Switching Panels and good swing practice..Swi

    Hi all,
    I have a GUI in which one of the panels needs to change, based on what "mode" the program is currently in.
    I've written code to do this but am wondering if it is good practice and if there are any easier ways you can suggest.
    In particular, the use of validate/+revalidate+ and repaint. And also how I can use pack, because last time I tried it didn't work that well.
    Thanks,
    KrimsonEagl
    public class SwitchingPanels extends JFrame implements ActionListener {
         private JDesktopPane desktopPane;
         private JPanel buttonPanel;
         private JPanel buttonPanelMain;
         private JPanel currentPanel = new JPanel();
         private enum Mode {
              MODE1, MODE2, MODE3
         private Mode mode = Mode.MODE1;
         private Map<Mode, JPanel> buttonMap;
         public SwitchingPanels() {
              // Set up GUI.
              super("Switching Panels");
              setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
              setSize(1024, 768);
              desktopPane = new JDesktopPane();
              add(desktopPane, BorderLayout.CENTER);
              buttonPanel = new JPanel();
              buttonPanel.setBorder(BorderFactory.createEtchedBorder());
              BoxLayout layout = new BoxLayout(buttonPanel, BoxLayout.Y_AXIS);
              buttonPanel.setLayout(layout);
              buttonPanelMain = new JPanel();
              ButtonGroup buttons = new ButtonGroup();
              addToggleButton(buttonPanelMain, buttons, "Mode1");
              addToggleButton(buttonPanelMain, buttons, "Mode2");
              addToggleButton(buttonPanelMain, buttons, "Mode3");
              addButton(buttonPanelMain, "Quit");
              createButtonPanels();
              buttonPanel.add(buttonPanelMain);
              buttonPanel.add(new JSeparator(SwingConstants.HORIZONTAL));
              add(buttonPanel, BorderLayout.NORTH);
              setLocation(50, 50);
              setVisible(true);
              refreshButtons();
         private void createButtonPanels() {
              buttonMap = new HashMap<Mode, JPanel>();
              JPanel mode1Panel = new JPanel();
              addButton(mode1Panel, "1.1");
              addButton(mode1Panel, "1.2");
              buttonMap.put(Mode.MODE1, mode1Panel);
              JPanel mode2Panel = new JPanel();
              addButton(mode2Panel, "2.1");
              addButton(mode2Panel, "2.2");
              buttonMap.put(Mode.MODE2, mode2Panel);
              JPanel mode3Panel = new JPanel();
              addButton(mode3Panel, "3.1");
              addButton(mode3Panel, "3.2");
              buttonMap.put(Mode.MODE3, mode3Panel);
         private void refreshButtons() {
              buttonPanel.remove(currentPanel);
              currentPanel = buttonMap.get(mode);
              buttonPanel.add(currentPanel);
              buttonPanel.validate();
              buttonPanel.repaint();
         private JToggleButton addToggleButton(JPanel panel, ButtonGroup group,
                   String name) {
              JToggleButton button = new JToggleButton(name);
              button.addActionListener(this);
              group.add(button);
              panel.add(button);
              return button;
         public void actionPerformed(ActionEvent e) {
              String cmd = e.getActionCommand();
              if (cmd.equals("Mode1")) {
                   mode = Mode.MODE1;
                   refreshButtons();
              } else if (cmd.equals("Mode2")) {
                   mode = Mode.MODE2;
                   refreshButtons();
              } else if (cmd.equals("Mode3")) {
                   mode = Mode.MODE3;
                   refreshButtons();
    }

    Look up the CardLayout as it is probably your best option here.
    Best of luck!

  • A tool-switching panel disappears, when a dialog is displayed.

    We are currently developing the plug-in of Adobe Illustrator CS6.
    Our CS6 Plug-in displays a modal dialog in tool selection.
    Modal dialog appears when I change tools, and the tool-switching panel disappears.
    I do not want to display a modal dialog on changing tool.
    In the case of CS5, such a thing does not occur.
    Do you have any solution?

    After a bunch of grumbling, head-scratching, research, and experimentation, I identified a solution that works for us.
    The consistent condition for users with this problem was that they had Acrobat (any version, near as we can tell) installed.  The browser used the Acrobat print dialog to print .pdf, and that dialog is the one that doesn't work.  Those who had only Adobe Reader were OK, since its print dialog worked.
    The fix is to make the browser use Reader to process pdfs rather than Acrobat, and the Reader print dialog works great.
    In the cases where no Reader was installed (only Acrobat), we installed it, and the Reader install reconfigured the browser to use the Reader with pdfs, instead of Acrobat.  The Reader install also makes itself the default application for all the standard pdf file types.  We initially thought, where both Reader and Acrobat were already installed, we could just re-associate the files with Reader and that would also correct the browser behavior.  But the browser explicitly associates an application with a file type, and does not rely on the computer associations to make that determination.
    Unfortunately, we weren't able to figure out how to manually change that for IE 10 or 11.  Probably a registry hack for that, but we're not terribly interested in going there.  So, if the computer already had both Acrobat and Reader installed, we just removed and reinstalled Reader.  Presto, browser uses Reader and printing is fixed.
    Of course, the down side is that after a Reader install, double-clicking a pdf file will bring up Reader, not Acrobat.  We told Acrobat users to run Acrobat first and use File/Open, or to right-click the file and use Open with.  If they want to play around with the file associations themselves, well, that's up to them.
    TSN, thanks for the response.

  • Switching panels in diffrent states

    Hi all,
    I have a lot of panels which I'm switch between them using card layout.
    My problem is that the switching between the panels isn't constant and it is depent of the application current state.
    For example:
    STATE1: Screen1 (next -->) Screen2 (next -->)Screen3 (next -->) Screen1
    STATE2: Screen1 (next -->) Screen2 (next -->) Screen3 (next -->) Screen2
    STATE3: Screen2 -(next -->) Screen1 (next -->) Screen3 (next -->) Screen1
    Each STATE is the user choise from the main-menu and and the Screens are the panels which displayed using the CardLayout and (next -->) represent the order they displayed
    and so on...
    At the moment i'm using a lot of if-else but this is not a good technigue when adding new panels and states.
    Does any one can give me advise how to make this simplier ?
    Thank,
    hanoch

    Use a 2D array to store the screen switch info.
    String[][] switchBoard = new String[stateNum][stepNum];
    // ToDo: Initialize the array here ...
    switchBoard[2][3] = "Screen 3";
    // Flip screen
    yourCardLayout.show(yourPanel, switchBoard[state][step]);

  • Silver Shuffle - Switch Panel Area Is White And Not Green As Apple Adverts

    Hi everyone
    Just got the New Silver iPod Shuffle.
    Have a question about the top of the ipod - where the switch is, the colour is White and not Green as shown in the Apple store Pictures. Any idea?
    I wouldn't like to think its a fake. Reason asking is I have already had to send one back as it looked liked it had been tampered with - had loads of scratches on the back and the cable was missing.
    Look forward to hearing feedback on your purchases.
    Best regards and thanks C :0)

    I Feel a Plonk
    Thanks for that

  • Switching Panels

    I am not experienced in developing java application and am working on a product management system in java.
    My initial design is to create a JFrame as the parent container and load different forms and reports in the parent container once a time.
    Each form/report would be a class which extends JPanel and will be instantiated and added to the parent JFrame. They should be called by each other to be loaded and showed in the parent JFrame.
    My questions are:
    1/. Should I use CardLayout and add ALL the forms at the very beginning? That does not sound good as the application might grow big to have many forms and reports.
    2/. Becasue the GUI components (buttons etc) are added in separate form/report from separate classes, how to call from one form/report class to load another in the parent JFrame?
    3/. Any other ways to do the task and what is the common practice?
    Thanks!

    i have asked the 1st question previously.
    someone replied that using cardlayout is not viable.
    he did not give me alternative.
    one way is to serialize jpanel forms and invoke them when u need.
    if there is another alternative u come across then pls post
    i also need this answer.
    thanks and regards,
    z_idane

  • Panel Switching

    I am having trouble switching panels.
    http://www.elovitz.net/help.zip
    Please reference myJFrame.java where the panelSwitch method is defined, welcomePanel where the method is called, and testPanel what should be displayed after.
    The panel switch method works, but after the panels are switched the screen remains blank...until I resize the window. I've tried every combination of repaint, revalidate, and validate that I could think of. I appreciate any insight in this matter.
    Thanks!

    >
    I've looked into a card layout and would prefer not to use it...>Why not? Is it perhaps that a CardLayout is the simplest and most well designed layout for this, and you want to do it the most complex and poorly designed way?
    >
    A zip file does usually imply a lot of code...but this one is only a few lines, just in different files :)>So take the advice in the SSCCE, demote most classes to 'default' and include them in the single source file - that can then be the 'few lines' you can post to the forum (between code tags, please).

  • Tabs and Panels

    Hey again. I have a JTabbedPane, with buttons, and another, larger Panel to the right of it. I need to be able to change the main Panel when a button is clicked. Unfortunatly, when I add content to it, the change doesn't show up until I change tabs on my TabbedPane. Changing the background colour works instantly though. Any ideas?
    Thanks!

    Swing related questions should be posted in the Swing forum.
    The method revalidate() is undefined for the type Panel revalidate() is for Swing components.
    You shouldn't be mixing AWT components with Swing components. Panel is AWT. You should be using JPanel which is a Swing component.
    You could also consider using a CardLayout, which was designed for this purpose:
    http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

  • Event doesn't switch context after switching jpane & class

    Hi,
    I have (almost) managed the concept (tight) coupling. I switch panels on the display by invoking a method in the parent. However something strange occurs:
    I have a first panel with an actionListener, getting a user name.
    I have a second panel showing a simple list of choices 1 .. 2.. 3 .. also with an actionListener.
    When I switch the panels from the usernamepanel to the choicespanel I see the choicespanel,
    but making a choice and pressing <enter> tells me to put in a userID (I cleaned that field on the first panel).
    So the actionListener defined with the choicespanel is not 'in control'.
    And the actionListener with the username still is.
    Explicitly removing the actionListener from the first panel does not help (?!)
    Would you know what it is that I do not understand about this situation?
         public void checkUsername () {
              JPanel sign_in_pnl = new Sign_in(this);
              this.add(sign_in_pnl, "0,0,0,0");
              Sign_in.User.requestFocus();          
         public void switchComponent () {
              this.remove(1);          
              JPanel choose00 = new Choose00();
              this.add(choose, "0,0,0,0");
              Choose00.Selection.requestFocus();          
         }     

    You might get an answer, but I think you may have missed the message at the top of this forum:
    Thank you for any participation in this forum. Due to a lack of relevant activity, we have decided to archive this forum on June 16, 2006. For future posts on this topic, we suggest you use the Enterprise JavaBeans forum.
    Thank you for using Sun Forums.

  • JScrollPane resizing problem, I think...

    The Task
    I want to build a dialog that holds different option panels.
    Instead of using a JTabbedPane, I want to use a JTree to select among the different panels.
    I put the tree in a nice scroll pane, place the whole thing in the left side of
    the dialog. I think I have the logic down except for one thing...
    The Problem
    Whenever I click a node when the JTree is expanded, it resizes itself. It does this so that words that go off to the right can be seen.
    I don't want this to happen, but I do have to revalidate the main panel for it to change.
    Apparently, just revalidating the main panel revalidates everything.
    The Question
    Is there a setting in the JTree or the JScrollPane that stops this from happening?
    I have tried to change the LayoutManager, but the same thing happens with GridBagLayout.
    I'll put example code in the following post so you can see my issue. I put the most pertinent code to the front, so that you don't have to read too deeply.
    Can anyone advise me?
    Thanks.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    import java.util.*;
    public class ScrollPaneProblem extends JDialog
       implements TreeSelectionListener
       private JButton jbClose;
       private JTree optionsTree;
       private MainPanel jpMain;
       private ActionListener terminator;
       public ScrollPaneProblem()
          // I would prefer that it stay this size.
          setSize( 535, 375 );
          setResizable( false );
          setTitle( "Preferences" );
          setupGui();
          setDefaultCloseOperation( DO_NOTHING_ON_CLOSE );
       protected void setupGui()
          Container contentPane = getContentPane();
             The left side of dialog will hold the option tree.
          optionsTree = buildTheTree();
          JScrollPane scrollPane = new JScrollPane( optionsTree );
          contentPane.add( scrollPane, BorderLayout.WEST );
             The center panel will hold another panel
             that changes according to what has been selected
             in the JTree.
          JPanel centerPanel = new JPanel( new BorderLayout() );
          Box bxButtons = buildTheButtonBox();
          centerPanel.add( bxButtons, BorderLayout.SOUTH );
          jpMain = new MainPanel();
          centerPanel.add( jpMain, BorderLayout.CENTER );
          contentPane.add( centerPanel, BorderLayout.CENTER );
       } // end setupGui()
          Changes the text on the main panel, according to what
          has been clicked in the JTree.
       public void valueChanged( TreeSelectionEvent evt )
          TreePath path = evt.getPath();
          Object obj = path.getLastPathComponent();
          if ( obj instanceof DefaultMutableTreeNode )
             DefaultMutableTreeNode node =
             (DefaultMutableTreeNode)obj;
             obj = node.getUserObject();
             // The problem happens when I do the following...
             jpMain.setText( obj.toString() );
             jpMain.revalidate();
             jpMain.repaint();
          } // end if ( a DefaultMutableTreeNode )
       } // end valueChanged( TreeSelectionEvent )
       private JTree buildTheTree()
          // First, build the parent nodes
          Object [] smurfNodes =
             "Smurfette", "Vanity", "Papa Smurf",
             "Greedy Smurf", "Lazy Smurf",
             "O.J., the ostracized orange smurf"
          ParentNode theSmurfs = new ParentNode(
                                  "The Smurfs", smurfNodes );
          Object [] dwarfNodes =
             "Doc", "Happy", "Dopey", "Sneezy",
             "Scratchy", "Sniffy", "Stuffy Head",
             "Fever", "So you can rest medicine"
          ParentNode theDwarfs = new ParentNode(
                                  "The Seven Plus Dwarfs", dwarfNodes );
          // These are all the nodes that go on the tree.
          Object [] theNodes =
             "Scooby Doo",
             "Inspector Gadget",
             "Mighty Mouse",
             "Captain Caveman",
             theSmurfs,
             theDwarfs
          JTree theTree = new JTree( theNodes );
          theTree.addTreeSelectionListener( this );
          return theTree;
       } // end buildTheTree()
       public Box buildTheButtonBox()
          Box box = Box.createHorizontalBox();
          box.add( Box.createHorizontalGlue() );
          // Make it so that we can close this JDialog.
          jbClose = new JButton( "Exit" );
          jbClose.addActionListener( terminator );
          box.add( jbClose );
          box.add( Box.createHorizontalGlue() );
          // help button that does absolutely nothing.
          JButton jbHelp = new JButton( "Help" );
          box.add( jbHelp );
          box.add( Box.createHorizontalGlue() );
          return box;
       } // end buildTheButtonBox()
       // Main entry point.
       public static void main( String [] args )
          JDialog dialog = new ScrollPaneProblem();
          dialog.setVisible( true );
       // So we can shut the dialog off
       static
          terminator =
          new ActionListener()
             public void actionPerformed( ActionEvent evt )
                System.exit( 0 );
    } // end ScrollPaneProblem class
       This MainPanel class goes in the middle of the dialog.
       My other program switches panels instead of using
       the same panel, but that's too much code to put here.
    class MainPanel extends JPanel
       String theText = "Tell me what to draw";
       Font theFont = new Font( "Sans Serif", Font.PLAIN, 12 );
       Dimension theSize;
       // Draws the selected text
       public void paintComponent( Graphics g )
          super.paintComponent( g );
          theSize = getSize( theSize );
          Font oldFont = g.getFont();
          g.setFont( theFont );
          g.drawString( theText, theSize.width / 10, theSize.height / 2 );
          g.setFont( oldFont );
       public void setText( String text )
          theText = text;
    } // end class MainPanel
       This helps with the JTree parent nodes.
    class ParentNode extends Vector
       String theName;
       public ParentNode( String name )
          this( name, null );
       public ParentNode( String name, Object [] values )
          theName = name;
          if ( values != null )
             addAll( Arrays.asList(values) );
       public String toString()
          return theName;
    } // end ParentNode class

  • 2 JApplets in One

    Hello I want to ask this: I have 1 Japplet working, this JApplet build some parameters that need the 2nd Applet, so my question is how can I pass the parameters to the 2nd applet and start the 2nd applet in the same screen of the first (without closing the first, becouse when the 2nd applet end have to return to the first applet), there is a way to do this?
    Thanks very much

    let's say you have 2 simple applets (based on panels)
    applet1
    import java.awt.*;
    import javax.swing.*;
    public class TestApplet extends JApplet
      public void init()
        setContentPane(new AppletPanel1());
    class AppletPanel1 extends JPanel
      public AppletPanel1()
        setPreferredSize(new Dimension(400,300));
        add(new JLabel("Applet 1"));
    }applet2
    import java.awt.*;
    import javax.swing.*;
    public class TestApplet extends JApplet
      public void init()
        setContentPane(new AppletPanel2());
    class AppletPanel2 extends JPanel
      public AppletPanel2()
        setPreferredSize(new Dimension(400,300));
        add(new JLabel("Applet 2"));
    }now put them together as a cardlayout, and switch between 1 and 2
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TestApplet extends JApplet
      public void init()
        JPanel holdingPanel = new JPanel(new BorderLayout());
        final CardLayout cl = new CardLayout();
        final JPanel cardlayoutPanel = new JPanel(cl);
        cardlayoutPanel.add("1",new AppletPanel1());
        cardlayoutPanel.add("2",new AppletPanel2());
        JButton btn = new JButton("Switch Panels");
        btn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            cl.next(cardlayoutPanel);
        holdingPanel.add(cardlayoutPanel);
        holdingPanel.add(btn,BorderLayout.SOUTH);
        getContentPane().setLayout(new GridBagLayout());
        getContentPane().add(holdingPanel,new GridBagConstraints());
    class AppletPanel1 extends JPanel
      public AppletPanel1()
        setPreferredSize(new Dimension(400,300));
        add(new JLabel("Applet 1"));
    class AppletPanel2 extends JPanel
      public AppletPanel2()
        setPreferredSize(new Dimension(400,300));
        add(new JLabel("Applet 2"));
    }

  • Vertical Scrolling and Horizontal Wrapping in a JEditorPane

    Hey guys,
    Some of you may recall my [post |http://forums.sun.com/thread.jspa?threadID=5418688] from a couple weeks back. In it, I learned how to force (or appear to force) the text of a JEditorPane to grow from the bottom-up instead of top-down (picture the difference between how a chat window grows to how a word document grows). The solution (which solves my original problem perfectly) involves simply placing the JEditorPane into the South region of a JPanel.
    That was all fine and dandy, until I tried putting long lines of text into the JEditorPane. It scrolled vertically when it should have, but the text simply ran off the right side of the JEditorPane instead of wrapping (or showing a horizontal scrollbar).
    After a gross amount of googling, I finally came across this old [post |http://forums.sun.com/thread.jspa?threadID=5318664] that seems to be related to my problem here. It hinted that I should set the width of the JPanel to match the width of the JScrollPane's Viewport. While that does indeed fix the problem with horizontal wrapping, it now creates a problem with the vertical scrolling (which works fine without the fix for horizontal wrapping)!
    I've tried setting the preferred height of the JPanel to just about everything I can think of: the height of the viewport, extremely large numbers, negative numbers, zero, itself, the height of the JEditorPane. But they all do the same thing: no vertical scrollbar ever pops up, even when the text is obviously too long to fit in the window.
    Here's an SSCCE demonstrating what I'm talking about:
    import javax.swing.*;
    import java.awt.*;
    public class EditorPaneTest {
        public EditorPaneTest() {
             JFrame frame = new JFrame("EditorPane Test");
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             JEditorPane textComponent = new JEditorPane();
             textComponent.setContentType("text/html");
             String text =
                  "This sentence should wrap and not cause the horiztonal scroll bar to display.<br/>"
                  + "<br/>This<br/>sentence<br/>should<br/>cause<br/>"
                  + "the<br/>vertical<br/>scroll<br/>bar<br/>to<br/>display.<br/>";
             textComponent.setText(text);
             JPanel panel = new JPanel(new BorderLayout());
             //the purpose of putting the JEditorPane in a JPanel
             //is to force it to the bottom with BorderLayout
             panel.add(textComponent, BorderLayout.SOUTH);
             JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
             //this line enables wrapping
             //but disables vertical scrolling
             //(comment it out to switch)
             panel.setPreferredSize(new Dimension(scrollPane.getViewport().getWidth(), scrollPane.getViewport().getHeight()));
             frame.add(scrollPane);
             frame.setSize(100, 200);
             frame.setVisible(true);
        public static void main(String[] args) {
            new EditorPaneTest();
    }As always, any pointers / suggestions / criticisms you can give me are greatly appreciated.
    Thanks again,
    Kevin

    camickr wrote:
    You need create a custom panel that implements the Scrollable interface. The key method to override to give you the behaviour you desire is the getScrollTracksViewportWidth() to return "true". This effectively fixes the width of the JEditorPane to the width of the viewport to wrapping is done as expected.That does handle the wrapping and scrolling, but it breaks the original problem: keeping a JEditorPane at the bottom of a JPanel. Using the ScrollablePanel you posted, the JEditorPane now stays at the top of the Panel instead of growing from the bottom.
    To see what I'm talking about, check out this code (the only difference between this and the previous code is the addition of your suggestion):
    import javax.swing.*;
    import java.awt.*;
    public class EditorPaneTest {
        public EditorPaneTest() {
             JFrame frame = new JFrame("EditorPane Test");
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             JEditorPane textComponent = new JEditorPane();
             textComponent.setContentType("text/html");
             String text =
                  "This sentence should wrap and not cause the horiztonal scroll bar to display.<br/>"
                  + "<br/>This<br/>sentence<br/>should<br/>cause<br/>"
                  + "the<br/>vertical<br/>scroll<br/>bar<br/>to<br/>display.<br/>";
             textComponent.setText(text);
             ScrollablePanel panel = new ScrollablePanel();
             panel.setLayout(new BorderLayout());
             //the purpose of putting the JEditorPane in a JPanel
             //is to force it to the bottom with BorderLayout
             panel.add(textComponent, BorderLayout.SOUTH);
             JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
             //this line enables wrapping
             //but disables vertical scrolling
             //(comment it out to switch)
            //panel.setPreferredSize(new Dimension(scrollPane.getViewport().getWidth(), scrollPane.getViewport().getHeight()));
             frame.add(scrollPane);
             frame.setSize(100, 200);
             frame.setVisible(true);
        public static void main(String[] args) {
            new EditorPaneTest();
         public class ScrollablePanel extends JPanel
              implements Scrollable
              public Dimension getPreferredScrollableViewportSize()
                   return getPreferredSize();
              public int getScrollableUnitIncrement(
                   Rectangle visibleRect, int orientation, int direction)
                   return 20;
              public int getScrollableBlockIncrement(
                   Rectangle visibleRect, int orientation, int direction)
                   return 60;
              public boolean getScrollableTracksViewportWidth()
                   return true;
              public boolean getScrollableTracksViewportHeight()
                   return false;
    }Resize the window to make it taller. The text should stay at the bottom of the window, but now it stays at the top. I tried using a BoxLayout on the ScrollablePanel instead, and adding a Box.createGlue( ) before adding the JEditorPane. But that didn't change anything.

  • Setvisible with java 1.6.11 and up

    Help please!!!
    We have an application that switches out panels in a JSplitPane. One of the panels is a very large JScrolledPane and when setting the visibility to false it can lock the application 30-60 seconds. This all started happening with the 1.6.11 update. Has anyone seen this or have any clues on why?
    Thanks,
    Mike

    Thanks for the reply. And here you go. But, now I have a bigger problem. This works for 1.5 thru 1.6.14!!! Granted our panels are move complex, but it still should not lock up the application during the remove call.
    Thanks again,
    mike
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class RemoveExample {
    static JFrame frame = new JFrame("Remove Issue");
    static JSplitPane mainPanel = new JSplitPane();
    static JSplitPane panel1 = new JSplitPane();
    static JSplitPane panel2 = new JSplitPane();
    public static void main(String args[]) {
         JPanel buttonPanel = new JPanel(new FlowLayout());
         JButton button = new JButton("Switch Panels");
         button.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              if (panel1.isVisible()) {
              mainPanel.remove(panel1);
              panel1.setVisible(false);
              mainPanel.setBottomComponent(panel2);
              panel2.setVisible(true);
              } else {
              mainPanel.remove(panel2);
              panel2.setVisible(false);
              mainPanel.setBottomComponent(panel1);
              panel1.setVisible(true);
         buttonPanel.add(button);
         mainPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
         mainPanel.setTopComponent(buttonPanel);
         panel1.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
         panel1.setLeftComponent(new JScrollPane(new JTree()));
         panel1.setRightComponent(new JLabel("small panel"));
         JTabbedPane tabs = new JTabbedPane();
         JPanel thumbnails = new JPanel(new GridLayout(0, 5, 10, 10));
         DefaultTableModel dtm = new DefaultTableModel();
         dtm.addColumn("Label");
         dtm.addColumn("Name");
         dtm.addColumn("Gallery");
         dtm.addColumn("Owner");
         dtm.addColumn("Uploaded");
         dtm.addColumn("Size(KB)");
         JTable table = new JTable(dtm);
         tabs.addTab("Thumbnails", new JScrollPane(thumbnails));
         tabs.addTab("List", new JScrollPane(table));
         panel2.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
         panel2.setLeftComponent(new JScrollPane(new JTree()));
         panel2.setRightComponent(tabs);
         mainPanel.setBottomComponent(panel1);
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
         frame.setSize(1000, 800);
         frame.setVisible(true);
         LoadThread loader = new LoadThread(thumbnails, table);
         loader.start();
    public static class LoadThread extends Thread {
         JPanel thumbs;
         JTable table;
         public LoadThread(JPanel thumbs, JTable table) {
         this.thumbs = thumbs;
         this.table = table;
         public void run() {
         DefaultTableModel dtm = (DefaultTableModel)table.getModel();
         for (int i = 0; i < 4000; i++) {
              JLabel label = new JLabel("image " + i);
    // set image icon.
              //label.setIcon(new ImageIcon("image.jpg"));
              label.setVerticalTextPosition(SwingConstants.BOTTOM);
              label.setHorizontalTextPosition(SwingConstants.CENTER);
              thumbs.add(label);
              dtm.insertRow(i, new String[]{ "image " + i, "Name", "Gallery",
                             "Owner", "Uploaded", "Size(KB)" } );
    Edited by: Pegasus-3326 on Jun 25, 2009 4:38 AM

Maybe you are looking for