Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2006

Tip: Looking for answers? Try searching our database.

Problem about JScrollPane

Thread view: 
ashwinijain - 25 Nov 2006 08:52 GMT
hello,
i am preparing software in which i have used many components like
jtable, jlabel etc..
i have added all these components to jpanel.
and i want the scrolled window but i am not able to get this...
code is...
class BillingSoftware extends JPanel /*implements ActionListener */
{
.................. //components are added here
}

b=new BillingSoftware();
JFrame myFrame=new JFrame();
myFrame.getContentPane().setLayout(null);
m.b.setBounds(0,0,1000,3200);
JScrollPane pane=new JScrollPane();
pane.getViewport().add(m.b);
pane.setBounds(0,0,1000,3200);
myFrame.getContentPane().add(pane);
myFrame.getContentPane().setBackground(Color.white);
myFrame.setSize(1000,3200);
myFrame.show();
hiwa - 25 Nov 2006 09:22 GMT
> b=new BillingSoftware();
> JFrame myFrame=new JFrame();
> myFrame.getContentPane().setLayout(null);
Bad practice. It cripples Java GUI heart and brain.

> m.b.setBounds(0,0,1000,3200);
May be wrong syntax.

> JScrollPane pane=new JScrollPane();
> pane.getViewport().add(m.b);
Wrong.

> pane.setBounds(0,0,1000,3200);
Just a consequence from null layout. Don't do that.

> myFrame.getContentPane().add(pane);
> myFrame.getContentPane().setBackground(Color.white);
> myFrame.setSize(1000,3200);
> myFrame.show();
Don't use deprecated method.
RedGrittyBrick - 25 Nov 2006 12:22 GMT
> hello,
>  i am preparing software in which i have used many components like
[quoted text clipped - 10 lines]
> JFrame myFrame=new JFrame();
> myFrame.getContentPane().setLayout(null);

Ugh! null layouts are evil evil evil.

> m.b.setBounds(0,0,1000,3200);

What is m?

> JScrollPane pane=new JScrollPane();
> pane.getViewport().add(m.b);
> pane.setBounds(0,0,1000,3200);

I think this is a bad thing (tm)

> myFrame.getContentPane().add(pane);
> myFrame.getContentPane().setBackground(Color.white);

I suspect you should be doing that to pane?

> myFrame.setSize(1000,3200);

I think this too is a bad thing (tm)

> myFrame.show();

When posting problems to newsgroups ALWAYS give a Small Self-contained
Complete Compilable Example (SSCCE) like this one (which scrolls nicely) ...

import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class BillingSoftware extends JPanel{

    BillingSoftware () {
        // Use simple ugly GridLayout for demo purposes.
        // See http://www.miglayout.com/ for my favourite today.
    // For a nicer layout, change one line below to
    // setLayout(new MigLayout("wrap 2"));
        setLayout(new GridLayout(6,2));
        setBackground(Color.WHITE);
        add(new JLabel("Foo"));
        add(new JTextField("apples", 10));
        add(new JLabel("Bar"));
        add(new JTextField("apples", 10));
        add(new JLabel("Baz"));
        add(new JTextField("apples", 10));
        add(new JLabel("Qux"));
        add(new JTextField("apples", 10));
        add(new JLabel("Zip"));
        add(new JTextField("apples", 10));
        add(new JLabel("Zap"));
        add(new JTextField("apples", 10));
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable(){
            public void run() {
                BillingSoftware b=new BillingSoftware();
                JScrollPane pane=new JScrollPane(b);
                JFrame myFrame=new JFrame();
                Container c = myFrame.getContentPane();
                c.add(pane);
                myFrame.setSize(200,150); // best is myFrame.pack()
                myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                myFrame.setVisible(true);
            }
        });
    }
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.