JSplitPane with 2 JScrollPanes sincroniced

Hi everyone,
I have a problem, and I haven't been able to solve it yet, this is it: I have a SplitPane, on its left side I have a jTable, and on its rigth side I have a jPanel with labels, I need them to have independent horizontal Scrolls but I need one only vertical Scroll at the rigth so they move in a sincroniced way.
I've tried using one Scroll Pane for all the Split Pane but then I Scroll both the titles of the jTable and the jPanel and I need them where they are.
Now I have the split pane with two Scroll Panes one with the table and the other with the Panel I think I have to make one of my Scrolls listen to the other and scroll by what it hears but I don't know how to do that... Which method should I rewrite? what do I need to implement to listen to the Scroll in an other Scroll pane?
Can any one help me?

Create a ChangeListener and add it to the JViewPort of the first scrollpane, then update the viewport of the second scrollpane when you receive a ChangeEvent. If the underlieing data sources of the viewports are the same size you can simply copy the height of the location of the first viewport to the second, if they are not the same you have to add some compensation for this. Look at the getViewPosition() and setViewPosition() methods of JViewPort.
Jurgen

Similar Messages

  • Problem of JSplitPane with ScrollPane

    Does JSplitPane work with ScrollPane?i am writing 2 ScrollPanes in a JSplitPane,but i can not move the bound.Thanks!

    It might be a little too late but I will put my 2 cents anyway...
    There is a scenario where mixing ScrollPane and JSplitPane is needed (unless you create your own AWTSplitPane): when you need to contain a heavyweight component (AWT) with a ScrollPane, you cannot use JScrollPane, that's for sure.
    The JSplitPane does not work because the minimumSize of the ScrollPane is set to its size and therefore JSplitPane won't reduce the component under its minimum size. The solution is to extend ScrollPane and override getMinimumSize method to whatever minimum size you decide.

  • JPopupMenu with a JScrollPane

    I have couple of questions
    1. I want to add a JScrollPane to JPopupMenu, doing this would not make the JPopupMenu visible. Is this doable?
    2. this is not related to question 1
    I have a JPOpupMenu with JMenuItems. When I select one of items and the item selected , I append the String to a JTextArea.
    The focus goes back to th beginning of the textArea, I want the focus to be at the end of string that is appended to the textArea.
    thanx

    I might sounding dense here, but I tried all the suggestions, it does not help. The textArea does not even get displayed.
    Also I noticed another thing, the JtextArea is registered with a mouseListener. But when I right click on JTextField , I get teh popup. Which is strange.
    I have attached the code with the above suggestions.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    public class TextChooserDemo extends JFrame{
         private JTextField field;
         private JLabel label1;
         private JLabel label2;
         private JPanel aPanel ;
         private JPanel bPanel;
         private JTextArea textArea;
        private TextChooser chooser;
        public TextChooserDemo() {
            initComponents();
            chooser=new TextChooser(this,textArea);
        private void initComponents() {
              field = new JTextField(20);
              label1 = new JLabel("Label1");
              textArea = new JTextArea();
              aPanel = new JPanel();
              aPanel = new JPanel();
              aPanel.setLayout(new BorderLayout());
              aPanel.add(label1, BorderLayout.WEST);
              aPanel.add(field, BorderLayout.CENTER);
              label2 = new JLabel("Label2");
              bPanel = new JPanel();
              bPanel.setLayout(new BorderLayout());
              bPanel.add(label2, BorderLayout.WEST);
              aPanel.add(textArea, BorderLayout.CENTER);
            setTitle("Text-Chooser Demo");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            getContentPane().add(aPanel,BorderLayout.NORTH );
            getContentPane().add(bPanel,BorderLayout.CENTER);
            //getContentPane().add(aPanel );
            //getContentPane().add(bPanel);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-500)/2, (screenSize.height-350)/2, 500, 350);
        public static void main(String args[]) {
            new TextChooserDemo().setVisible(true);
    class TextChooser extends JWindow {
        public TextChooser(JFrame parent, JTextArea textArea){
            super(parent);
            this.parent=parent;
            this.textArea=textArea;
            initChooser();
        private void initChooser(){
            textArea.addMouseListener(new MouseAdapter() {
                public void mouseReleased(MouseEvent evt) {
                    textAreaMouseReleased(evt);
            popupScrollPane = new JScrollPane();
            popupList = new JList();
            popupList.setModel(new AbstractListModel() {
                String[] strings = { "java ", "is ", "cool ", "and ", "nice ", "to ", "have ", "with ", "no ", "error ", ".\n" };
                public int getSize() { return strings.length; }
                public Object getElementAt(int i) { return strings; }
    popupList.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent evt) {
    popupListAction(evt);
    popupScrollPane.setViewportView(popupList);
    getContentPane().add(popupScrollPane);
    private void popupListAction(ListSelectionEvent evt) {
    if (evt.getValueIsAdjusting() == false) {
    textArea.append((String)popupList.getSelectedValue());
    try{
    textArea.setCaretPosition(textArea.getLineEndOffset(textArea.getLineCount()-1));
    }catch(BadLocationException ex){ex.printStackTrace();}
    setVisible(false);
    textArea.requestFocus();
    private void textAreaMouseReleased(MouseEvent evt) {
    Point pnt = evt.getPoint();
    int x = (int)pnt.getX()+(int)parent.getX();
    int y = (int)pnt.getY()+(int)parent.getY()+20;
    if( !contains(x,y) ){
    setVisible(false);
    if(evt.isPopupTrigger()){
    setBounds(x,y,200,100);
    setVisible(true);
    private JFrame parent;
    private JTextArea textArea;
    private JScrollPane popupScrollPane;
    private JList popupList;
    thnx again!!!

  • A small problem with a JScrollPane and child windows

    Hi !
    I have created a customized JComponent inside a JScrollPane and when my application starts I create two JTextField's that I put in the JComponent and so far it all works fine to start with, but when ever the JComponent is redrawn after that the JTextField's are overdrawn or at least are not visible any longer...
    Do I need to repaint the sub components of my own JComponent myself or am I doing something very wrong here ?
    a JScrollPane
    a JComponent with some drawing going on in paint()
    a JTextField
    another JTextField
    Mikael

    Ooppps !
    Forget about it, I forgot to put a super.paint( g) at the top of my paint method, that was the problem.
    Mikael

  • JSplitPane with external panel

    Hi,
    I want to use a JSplitPane wich:
    Displays a JTree in the left-component
    Displays application selected from JTree in right-component
    Sounds simple. The right-component has a 'card-deck' which will
    swap whenever an other application is selected in the JTree.
    I have written a short test which does almost exactly what I want.
    Problem is that a panel, which was a standalone Frame-app first,
    is not shown in the right-component (but it is running!)
    It seems that cannot put a standalone application (extending a JFrame) on a component.
    So I decided to change the application and use a JPanel in stead
    of a JFrame. The panel is accepted but isn't shown. (application is
    running though).
    I created a short testpanel_class which should be shown when
    the first app is selected from JTree.
    Current Result when JSplitPane-app is started
    ==> I get the 'home'-card first
    ==> When App2 is selected, I get correct card
    ==> When App1 is selected, the right-component is blank (app runs!)
    Herewith the codesnippet of my JSplitPane-app which is showing
    how I put the components on the left/right components:
    ===================================================
         private JSplitPane getJSplitPane() {
              if (jSplitPane == null) {
                   jLabel = new JLabel("Tekst");
                   jSplitPane = new JSplitPane();
                   jSplitPane.setLeftComponent(getJTree());               
                   myPanel.setLayout(new BorderLayout());
                   pCards.setLayout(cardlayout);
                   pCards.add("home", new JLabel("Home"));
                   pCards.add("App1", new SplitBasePanel());
                   pCards.add("App2", new JLabel("Menu2 Selected"));
                   myPanel.add(pCards, BorderLayout.CENTER);
                   myApp.getViewport().add(myPanel);
                   jSplitPane.setRightComponent(myApp);
              return jSplitPane;
    ===================================================
    And I swap the cards as follows:
    ===================================================
         public void valueChanged(TreeSelectionEvent event) {
              if (!firstRun){
    System.out.println
    ("Current Selection: " +
    jTree.getLastSelectedPathComponent().toString());
    if ((jTree.getLastSelectedPathComponent().toString()).equals("App 1")){
                   cardlayout.show(pCards, "App1");
    if ((jTree.getLastSelectedPathComponent().toString()).equals("App 2")){
                   cardlayout.show(pCards, "App2");
              firstRun = false;
    ======================================================
    Here is my application-panel to be shown
    =================================
    package application;
    import javax.swing.*;
    import java.awt.*;
    public class SplitBasePanel
         extends JPanel {
         // Panel Layout
         private JPanel c = new JPanel();
         // APPLICATION BASE FRAME
         public SplitBasePanel() {
         // Create Application panel
         c.setLayout(new BorderLayout());
         // Initialize CardDeck with basepanels
         c.add(new JLabel("my External Application"), BorderLayout.CENTER);
    }

    a) Sorry for the "code"-formatting, i just copy & paste from my developersoft.
    b) SSCCE ????
    c) I have placed this in this forum because it is not only a question about usage of swing components but also about the concept I try to implement. Maybe what I'm trying to do is just not the right concept !
    d) what do you mean by your final remark (history reply postings)?
    I do not make daily usage of this Developer Forums. So please forgive me when I don't follow the rules completely. I will post the message again in the SWING-forum and try to use the correct formatting.
    Patrick.

  • Problem with the JScrollPane...

    Hi there!
    I have a little problem controling the JScrollPane.
    In some class - which extends the JPanel class - I build the GUI within the constructor.
    This class is later included by another class into the center of a border layout. Now when
    I make this whole window visible, everything looks fine except that the scrollpane scrolled
    down to approx. 3/4 of the panel, but I want the Scrollpane to scroll all the way to the top...
    I already tried to manage this by using
    scrollPane.getVerticalScrollBar().setValue(0);
    But this does not do anything as long as I am calling this function from within the constructor.
    When I trigger this function by pressing some JButton it works fine!
    I guess this has something to do with the way Java paints the Frames and the Panels. And that
    maybe the Scrollpane is not yet existend as such when I try to scroll all the way to the top....
    Do you have any suggestions??
    Thx in advance!!

    But this does not do anything as long as I am calling this function from within the constructor.
    scrollPane.getVerticalScrollBar().setValue(0);Try wrapping the above line in a SwingUtilities.invokeLater(...)
    or maybe using
    component.scrollRectToVisible(...);

  • JSplitPane with AWT component

    Hi all,
    I have a problem with JSplitPane, I use it with JPanel as right component and an AWT component as left Component, so when I move The Divider of the JSplitPane it hides under the AWT component not on the top of it.
    I know that result from problem of heavy weight component and light weight component .. but my question is there any work arround I can do to make the Divider appear on the top of the AWT component??
    Thanks,

    You've been given an idea: DO NOT MIX AWT and SWING Components.
    Why do you need to mix them? What is the AWT component?
    If it's something you wrote yourself, then you can change it. If it's not, decompile it and change it. Anyone who can't provide a Swing version of their stuff at this point is out of business and shouldn't care what you do with it.
    If it's some Canvas subclass, you can make it a Swing component by changing 2 lines: extends JPanel instead of Canvas and change paint() to paintComponent().
    is there any work arround I can do to make the Divider appear on the
    top of the AWT component??definitely not, unless you make the divider a heavyweight component somehow.

  • JSplitPane with JFrame

    Hi All,
    I have a JSplitPane on which left Component is JTree and right component is multiple mini JFrames...So after adding frames on the right side i am able to drag tha frame whereever i want..If i want to restrict it only into the right window available..How can i do that??
    Thanks in advance.
    regards,
    Viswanadh

    Ya Camic...I got an example when i searched in google...Here it is.
    import javax.swing.*; 
    public class DTopTest extends JFrame { 
        public static void main( String[] arg ) { 
            new DTopTest(); 
        public DTopTest() { 
            JDesktopPane desktop = new JDesktopPane(); 
            setContentPane( desktop ); 
            JInternalFrame top = new JInternalFrame( "Top" ); 
            top.setBounds( 10, 10, 200, 200 ); 
            top.setVisible( true ); 
            desktop.add( top, new Integer( 10 ) ); 
            JInternalFrame normal1 = new JInternalFrame( "Normal 1" ); 
            normal1.setBounds( 100, 100, 300, 300 ); 
            normal1.setVisible( true ); 
            desktop.add( normal1 ); 
            JInternalFrame normal2 = new JInternalFrame( "Normal 2" ); 
            normal2.setBounds( 300, 300, 300, 300 ); 
            normal2.setVisible( true ); 
            desktop.add( normal2 ); 
            setDefaultCloseOperation( EXIT_ON_CLOSE ); 
            setSize( 500, 500 ); 
            setVisible( true ); 
        private class TopFrame extends JInternalFrame { 
            TopFrame( String title ) { 
                super( title ); 
            public boolean isSelected() { 
                return true; 
    }  In this example InternalFrames are added to Main frame with the help of JDesktopPane..My question is apart from me adding JInternalFrames i will be adding some textfields or labels on the same..So i require GridLayout to be enabled for the container,but JDesktopPane doesnt support either
    setLayout(new GridLayout(0,1,5,5));
    or
    JDesktopPane jdp=new JDesktopPane() //argument as GridLayout.So i just wanna know how to do this??
    Thanks in advance.
    regards,
    Viswanadh

  • Probably an easy problem with a JScrollPane

    Hi,
    I would like to scroll a JScrollPane from outside my JScrollPane, of course I could used the setValue of the JScrollBar but I would prefer to simulate a click on the up/down buttons of my bar. Does anyone can help me?
    Thanks.
    S�bastien

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class souptier extends JFrame implements ActionListener {
      JScrollPane scrollPane;
      JButton
        upButton,
        downButton;
      JRadioButton
        unitButton,
        blockButton;
      public souptier() {
        upButton = new JButton("Up");
        upButton.addActionListener(this);
        downButton = new JButton("Down");
        downButton.addActionListener(this);
        ButtonGroup group = new ButtonGroup();
        unitButton = new JRadioButton("unit");
        group.add(unitButton);
        blockButton = new JRadioButton("block");
        blockButton.setSelected(true);
        group.add(blockButton);
        JPanel buttonPanel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(0,0,0,45);
        buttonPanel.add(upButton, gbc);
        buttonPanel.add(downButton, gbc);
        gbc.insets = new Insets(0,0,0,0);
        buttonPanel.add(unitButton, gbc);
        buttonPanel.add(blockButton, gbc);
        JPanel panel = new JPanel(new GridBagLayout());
        gbc.insets = new Insets(0,50,0,0);
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.anchor = gbc.WEST;
        for(int j = 0; j < 20; j++)
          panel.add(new JLabel(String.valueOf(j)), gbc);
        panel.setBackground(Color.yellow);
        panel.setPreferredSize(new Dimension(1000,1000));
        scrollPane = new JScrollPane(panel);
        scrollPane.getVerticalScrollBar().setUnitIncrement(50);
        scrollPane.getVerticalScrollBar().setBlockIncrement(200);
        getContentPane().add(scrollPane, "Center");
        getContentPane().add(buttonPanel, "South");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(400,300);
        setLocation(300,400);
        setVisible(true);
      public void actionPerformed(ActionEvent e) {
        JButton button = (JButton)e.getSource();
        int inc;
        if(button == upButton) {
          JScrollBar vertBar = scrollPane.getVerticalScrollBar();
          int currentValue = vertBar.getValue();
          if(unitButton.isSelected())
            inc = vertBar.getUnitIncrement(-1);
          else
            inc = vertBar.getBlockIncrement(-1);
          if(currentValue + inc < vertBar.getMaximum())
            vertBar.setValue(currentValue + inc);
          else
            vertBar.setValue(vertBar.getMinimum());
        if(button == downButton) {
          JScrollBar vertBar = scrollPane.getVerticalScrollBar();
          int currentValue = vertBar.getValue();
          if(unitButton.isSelected())
            inc = vertBar.getUnitIncrement(1);
          else
            inc = vertBar.getBlockIncrement(1);
          if(currentValue - inc > vertBar.getMinimum())
            vertBar.setValue(currentValue - inc);
          else
            vertBar.setValue(vertBar.getMinimum());
      public static void main(String[] args) {
        new souptier();
    }

  • JOptionPane setMaximumSize with a JScrollPane as the object doesn't work

    I am trying to use a JOptionPane for error messages. I'm trying to make the JOptionPane dialog be a minimum of 500x100 and a maximum size of 500x450 depending on the amount of text in the JTextArea inside the JScrollPane that's being passed into JOptionPane. I've tried both JOptionPane.showMessagePane(), and instantiating a JOptionPane and then setting its maximumSize, neither of which work as expected. Here is the relevant code:
    public static void doCommonMessagePane( Component parent, String optMsg,
                                             String title, int msgType )
        JTextArea msg = new JTextArea( optMsg );
        JScrollPane jsp = new JScrollPane( msg );
        initOptionPaneComponents( msg, jsp );
        Dimension maxSize =new Dimension(500, 450) ;
        JOptionPane op = new JOptionPane(jsp, msgType);
        op.setMaximumSize(maxSize);
        op.revalidate();
        op.setVisible(true);
    //here is me also trying showMessageDialog
    //    JOptionPane.showMessageDialog(parent, jsp, title, msgType);
      private static void initOptionPaneComponents( JTextArea ta, JScrollPane sp )
              Color bg = UIManager.getColor( "Panel.background" );
              Dimension jspSz = new Dimension( 500, 75 );
              Dimension max = new Dimension( 500, 450 );
              ta.setMargin( new Insets( 5, 10, 10, 5 ) );
              ta.setColumns( 50 );
              ta.setLineWrap( true );
              ta.setWrapStyleWord( true );
              ta.setEditable( false );
              ta.setEnabled( false );
              ta.setBackground( bg );
              ta.setDisabledTextColor( Color.black );
              ta.setFont( UIManager.getLookAndFeelDefaults().getFont( "Dialog" ) );
              ta.setMaximumSize(max);
              ta.setMinimumSize(jspSz);
              sp.getViewport().add( ta );
         //sp.setPreferredSize( jspSz );
              sp.getViewport().setMaximumSize(max);
              sp.getViewport().setMinimumSize(jspSz);
              sp.setBorder( BorderFactory.createLoweredBevelBorder() );
              sp.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
         //     sp.setPreferredSize( jspSz );
           sp.setMinimumSize(jspSz);
              sp.setMaximumSize( max );
         }

    When the JScrollPane is placed into the CENTER position the JOptionPane ignores the maxSize of both the JScrollPane and the JTextArea and stretches both of these out to 500x700 so that all text is visible. You still miss the basic concept.
    The answer is it depends! First the size of the dialog needs to be determined.
    If you use dialog.pack() then the preferred size of all components is used to determine the size of the dialog and the scrollpane will be whatever preferred size you gave it. If you leave the preferred size at (0, 0) then the scrollpane and text area will be invisible.
    If you use dialog.setSize(???, ???), then the size of the scrollpane will be adjusted to fit the available space.
    The amount of text in the text area is irrelevant in determining the size of the scrollpane. It is relevant in determining whether scrollbars will appear or not once the scrollpane is displayed.
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting], so the posted code retains its original formatting.

  • Help needed with a JScrollPane

    In the next example I have a small problem. I want that my scrollbar scroll back to 0 (vertical scrollbar) when i click on a item in the JList.
    so to see what i meen, you have to take the following steps to recreate the situation.
    - run the program
    - click on a item
    - scroll the vertical scrollbar to the half
    - click on the other item
    - And now the scrollbar needs to scroll back to 0 (this doesn't happen).
    I hope somebody know what I have to change.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.WindowEvent;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    public class Main extends JFrame{
        GridLayout gridLayout2 = new GridLayout();
        GridLayout gridLayout3 = new GridLayout();
        JPanel SubPanel1 = new JPanel();
        JPanel SubPanel2 = new JPanel();
        JList list = new JList();
        JScrollPane scrollPane = new JScrollPane(SubPanel2);
        public Main() {
            enableEvents(AWTEvent.WINDOW_EVENT_MASK);
            try {
                jbInit();
            } catch (Exception ex) {
                ex.printStackTrace();
        public static void main(String[] args) {
            Main main = new Main();
            main.setVisible(true);
        private void jbInit() throws Exception {
            this.setTitle("HELP!!!!");
            this.setSize(350,350);
            this.getContentPane().setLayout(gridLayout2);
            this.setVisible(true);
            SubPanel2.setLayout(null);
            SubPanel1.setLayout(gridLayout3);
            this.getContentPane().add(list);
            SubPanel1.add(scrollPane);
            this.getContentPane().add(SubPanel1);
            ListModel listModel = new DefaultComboBoxModel(new String[] {
                                                           "Item One", "Item Two" });
            list.setModel(listModel);
            list.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent evt) {
                    listValueChanged(evt);
        protected void processWindowEvent(WindowEvent e) {
          super.processWindowEvent(e);
          if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            System.exit(0);
        int i =0;
        public void listValueChanged(ListSelectionEvent e) {
            if(e.getValueIsAdjusting() == true){
                SubPanel2.removeAll();
                JPanel SubPanel3 = new JPanel();
                SubPanel3.setBounds(0, 100, 300, 200);
                SubPanel3.setBorder(BorderFactory.createTitledBorder("Panel 1" + i));
                JTextArea textArea1 = new JTextArea();
                SubPanel3.add(textArea1);
                textArea1.setText("12345");
                textArea1.setPreferredSize(new java.awt.Dimension(250, 80));
                textArea1.setFocusable(false);
                textArea1.setEditable(false);
                JPanel SubPanel4 = new JPanel();
                SubPanel4.setBounds(0, 320, 300, 200);
                SubPanel4.setBorder(BorderFactory.createTitledBorder("Panel 2" + i));
                JTextArea textArea2 = new JTextArea();
                SubPanel4.add(textArea2);
                textArea2.setText("67890");
                textArea2.setPreferredSize(new java.awt.Dimension(250, 80));
                textArea2.setEditable(false);
                textArea2.setFocusable(false);
                i++;
                SubPanel2.add(SubPanel3);
                SubPanel2.add(SubPanel4);
                SubPanel2.setPreferredSize(new Dimension(300, 500));
                SubPanel2.updateUI();
    }Greetings, Remco

    scrollPane.getViewport().setViewPosition(new Point(0, 0));
    SubPanel2.updateUI();Note:
    1) First character of a variable name should not be upper cased. (ie. SubPanel2 should be subPanel2.
    2) There is no need to override processWindowEvents to exit the application. Simple use the JFrame method:
    setDefaultCloseOperation( EXIT_ON_CLOSE );

  • Advanced programmers, what is wrong with my JScrollPane?

    Hi,
    I wanted my JScrollPane to display what is drawn on my canvas (which may be large)by scrolling, but it says it doesn't need any vertical and horizontal scroll bars -- hence I can't view all of what I have drawn(a rectangle) by scrolling.Here is the code that has this effect
    import javax.swing.*;
    import java.awt.*;
    public class WhatsWrong extends JApplet{
    public void init(){
    Container appletCont = getContentPane();
    appletCont.setLayout(new BorderLayout());
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add(new LargeCanvas(),BorderLayout.CENTER);
    int ver = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int hor = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp = new JScrollPane(p,ver,hor);
    appletCont.add(jsp,BorderLayout.CENTER);
    class LargeCanvas extends Canvas{
    public LargeCanvas(){
    super();
    setBackground(Color.white);
    public void paint(Graphics g){
    g.drawRect(50,50,700,700);
    and the html code:
    <html>
    <body>
    <applet code="WhatsWrong" width = 300 height = 250>
    </applet>
    </body>
    </html>
    What shall I do?
    Thanks in advance.

    I have just found the solution from another guy on the
    forum. It is just to use JPanel instead of Canvas and
    set the size of the panel as suggested by the first
    response.
    Thanks all for your fast response!It's also better to only use Swing components when its alread a Swing gui. JPanel is the replacement for Canvas. I remember once when I tried to use a Canvas and a JMenubar. That didn't look too good, because when I clicked on a menu, the menuitems was displayed under the canvas.

  • CardLayout Problems

    When switching cards using the show() method some of the contents of the card is not shown. On the card that has the problem I have a JSplitPane with two JScrollPane's in the JSplitPane. In the JScrollPane's I use a JPanel with the null layout. The contents of the JScrollPane do not appear. If I start the applet showing the card with the problem everything shows fine. If I start the applet showing another card and then switch to the card in question this is when the problem occurs. Any advice would be greatly appreciated.

    Hey thanks for the response, I never thought anyone would touch this >one. :) you rock.np, that's what the forum is here for. And after all I'm just TRYING to help...;)
    according to what you said it really seems to be a resizing prob, 'cause
    Have you ever tried starting the applet with the
    prob-card on top, switching to another one and then
    switching back? what happens, the card is still ok?Yes, and everything is fine. this speaks quite in it's favor....
    If the applet does not change size however, no matter what card you start it with, this (could) mean two things (assuming that it is, in fact, a resizing problem):
    first possibiliy: other components within the card are resized to their downside when sarting with the prob-causing card so that it has enough space, when starting with the 'standard'-one they are not scaled down not leaving place for the rpob-causing card.
    second: it has to do with the embedding in the html environment, I mean, the size of the area grantet to the applet is absolutely constant, and when starting with the prob-causer a bit of the applets'border is cut off, just like putting a picture frame over a too big photograph...
    As for the second (possible) case: try to alter the embedding settings, in order to leave enough space to the applet or someting...
    And for the first:...well, I know it's a vague advice but...try to remove ANY other items from the applet leaving just the cards, and play around with it....
    I'll post as soon as something more productive crosses my mind..(but that will be after the xmas vacation, I guess ;D
    btw.: ever tried to run the same applet in a tabbed pane instead of the card layout and see what happens?
    p.s:merry xmas, so long...

  • JTable in JPanel in JTabbedPane in JScrollPane in JSplitPane problem

    I have a JSplitPane with a divider in the center; of which the top is a JPanel and the bottom is a JScrollPane that contains a JTabbedPane, for which each tab contains a JPanel which contains a JTable.
    When I move the divider up, so that it now takes up 75% of the JSplitPane, the JScrollPane and the JTabbedPane expand with the JSplitPane, but the JPanel that contains the JTable remains the same size that it had at the beginning.
    What I would like to see is more rows of the JTable as I move the divider to give the JScrollPane more room.
    Is there an easy way to keep all of the J components sizes in sync as the JSplitPane gets larger or smaller ? (JDK 1.3.1)

    Hi,
    The JPanels which you have inside each tab of the JTabbedPanes should have BorderLayout and the JScrollPanes which hold the JTables should be added with the BorderLayout.CENTER constraint. This will make sure that the JScrollPanes that contain the JTables occupy as much space as possible.
    Hope this helps,
    Ranga.

  • JSplitPane problem with Border layout

    I am using Swing utilities.
    I have a JFrame
    I am using Panel with BorderLayout(mainPanel)
    To this Panel i am adding a Button Panel which comprises of two JButtons.
    Now i am creating a BorderedLayout Panel (subPanel)and setting its size and adding it to the mainPanel to its West side.
    Now my requirement is having the Split Panel with JTree on left side Panel and Canvas on the right side Panel
    So i created a JScrollPane with Canvas attached to it with Always Scrollable option set for the right hand side Panel.
    For the left hand side Panel, i created the JPanel with JTree attached to it.
    I have passed these two components as parameters to the JSplitPane with Horizontal Split and added the splitPane to the subPanel.
    Now i got the Split Pane with JTree on the left side Panel and Canvas on the right side panel.
    Now my requirement is getting the Text Area and Progress /Status bar below the Split Pane.So first made a JTextArea with BorderLayout and added it to the subPanel to
    its South.To this TextArea i added a progress bar to show the status to its East.
    Everything till here were working fine.
    Problem is while i am moving the split pnae to its right side (towards Canvas ) the Canvas is getting shifted beyond the subPanel.
    How to solve this problem
    I will be thankful to you if anyone could give me the solution ASAP

    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

Maybe you are looking for

  • FRM-10221 Cannot read file PL000000-but there is no menu named PL000000 !!?

    Hi all! I'm having a problem wich will get me nervous! Here we have an application 100% generated from designer. The problem is that it have been started in questionnables ways ... there is 2 workarea to contains all the forms needed for the applicat

  • ABAP Proxy : Modification in Structure 2

    Hi, I try to modify a structure but i can not do that, because is "Proxy Structure (generated)", I excute the transaction SPROXY in order to modify this structure but i don't know how to find it Pls help , how to find the structure in this transactio

  • Business Partner Role  and Business Partner Grouping

    Hello Everybody! Business Partner Role  and Business Partner Grouping. Which correlation ist between this attributes existing. In which table are this infos stored, In order create I can use e.g. BUPA_CREATE_FROM_DATA but how is the way inversely. Su

  • Monitor goes to energy saving mode

    I have a macbook pro 13" (mid 2010) and i also bought the mini display port to vga adapter from apple, one day the computer went to sleep with and external monitor plugged in, and when i tried to wake up the computer the display still in energy savin

  • This is getting extremely aggravating! ATTN: Apple Support.

    This has been on the board many times, but there has yet been a reason why we haven't fixed it yet or how to fix it. Okay i downloaded the new update for iTunes and now it will not connect to the store. When I click the store link it wont load and th