Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

JPanel na JscrollPane

[es] :: Java :: JPanel na JscrollPane

[ Pregleda: 2999 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

x VITA x
Beograd

Član broj: 41277
Poruke: 57
*.nat-pool.bgd.sbb.co.yu.



Profil

icon JPanel na JscrollPane14.03.2005. u 20:28 - pre 231 meseci
dakle imam problem da namestim ova dva da rade..tacnije radi o skrolovanje ali se komponenta vidi i tamo gde ne treba...

Code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Main extends JFrame {
    
    public static void main(String[] args) {
    
        Main       app = new Main();
        
        Container cont = new Container();
        
        JButton buton =new JButton("aaa");
        
        cont.setLayout(new GridLayout(10,1));
        app.setLayout(new GridLayout(2,1));
        
        for(int i=0;i<10;i++)
         cont.add(new Button(Integer.toString(i)));
        
        JScrollPane scroll = new JScrollPane(cont,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        
        app.add(scroll);
        app.add(buton);

        
        app.setSize(200,200);
        app.setVisible(true);

    }
    
}


evo i kako izgleda
ovde

ovo mi pravi problem na jednom vecem programu a napravo sam ovaj manji da pokusam prvo tu da resim

aj ako neko ima ideju kako bio bih veoooma zahvalan
UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity. - Dennis Ritchie
 
Odgovor na temu

StMilan

Član broj: 5061
Poruke: 144
*.ptt.yu.



Profil

icon Re: JPanel na JscrollPane14.03.2005. u 22:11 - pre 231 meseci
JScrollPane radi sa light-weight componentama, znači samo Swing, ne AWT.
Ti koristiš java.awt.Container koji mislim da je light-weight (ne drži neki grafički resurs OSa) ali mnogo bitnije na njega dodaješ Button, koji je heavy-weight.
Umesto Button stavi JButton i sve će da radi. I još bolje stavi JPanel umesto Container.

Ja samo ovo probao i ok radi:
Code:

import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class Main extends JFrame {

    public static void main(String[] args) {

        Main app = new Main();

        JPanel cont = new JPanel();

        JButton buton = new JButton("aaa");

        cont.setLayout(new GridLayout(10, 1));
        app.setLayout(new GridLayout(2, 1));

        for (int i = 0; i < 10; i++)
            cont.add(new JButton(Integer.toString(i)));

        JScrollPane scroll = new JScrollPane(cont,
                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

        app.add(scroll);
        app.add(buton);

        app.setSize(200, 200);
        app.setVisible(true);

    }

}
 
Odgovor na temu

x VITA x
Beograd

Član broj: 41277
Poruke: 57
*.nat-pool.bgd.sbb.co.yu.



Profil

icon Re: JPanel na JscrollPane14.03.2005. u 22:38 - pre 231 meseci
AAAAAAAAAA!!!
mrzim glupe awt komponente koje koriste sistemske resurse....

jos ja gledao za lake /teske..... ali mi nije palo na pamet za to..

Tnx man punooo...
ustedeo si mi puno vremena.. :)
UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity. - Dennis Ritchie
 
Odgovor na temu

nemnesic
nemnesic
Software Developer
Vranje Florida

Moderator
Član broj: 44355
Poruke: 802
*.sfcc.edu.



+64 Profil

icon Re: JPanel na JscrollPane14.03.2005. u 23:10 - pre 231 meseci
pogledaj ovo radi:

Code:

import java.awt.*;

import javax.swing.*;



public class Main extends JFrame {
    
    JPanel cont = new JPanel();
    JButton button = new JButton("aaa");
    
    public Main()
    {
        super("testing");
        Container c = getContentPane();
        c.setLayout(new GridLayout(2, 1));
        cont.setLayout(new GridLayout(10, 1));
        
        for (int i = 0; i < 10; i++)
           cont.add(new JButton(Integer.toString(i)));
           
        JScrollPane scroll = new JScrollPane(cont, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        c.add(scroll);
        c.add(button);
        setSize(200, 200);
        setVisible(true);
        }

   public static void main(String args[]) {
    
         Main window = new Main();

         
         window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
         window.pack();
         window.show();
    }

}


nn
 
Odgovor na temu

[es] :: Java :: JPanel na JscrollPane

[ Pregleda: 2999 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.