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

JMenu i JTable zajedno?

[es] :: Java :: JMenu i JTable zajedno?

[ Pregleda: 2177 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

DusanSukovic
Dušan Šulović
Na krevetu

Član broj: 35637
Poruke: 1371

Sajt: www.MotoBoem.RS


+460 Profil

icon JMenu i JTable zajedno?13.11.2005. u 09:11 - pre 224 meseci
Zelim da uradim da mi tabla stoji ispod menija, ne znam kako da to izvedem uz pomoc Layout Managera, nekad sam to malo znao - ali sam zaboravio. Ovako dobijam da mi meni lezi sa desne strane, a tabela sa lijeve pomaknuta skroz prema vrhu. Ima li ko neku ideju? Znam da ovo uzasno izgleda ;-)


Code:

//  IntroExample.java
// An introduction to building menus and menu items.  Accelerators and
// mnemonics are added to various items.
//
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class IntroExample extends JMenuBar {

    String[] fileItems = new String[] { "Add Client", "Edit Client", "Delete Client", "Print" };
    String[] editItems = new String[] { "Undo", "Cut", "Copy", "Paste" };
    char[] fileShortcuts = { 'N','O','S','X' };
    char[] editShortcuts = { 'Z','X','C','V' };

    public IntroExample() {

        JMenu fileMenu = new JMenu("Clients");
        JMenu editMenu = new JMenu("Edit");
        JMenu otherMenu = new JMenu("Other");
        JMenu subMenu = new JMenu("SubMenu");
        JMenu subMenu2 = new JMenu("SubMenu2");

        //  Assemble the File menus with mnemonics
        ActionListener printListener = new ActionListener() {
              public void actionPerformed(ActionEvent event) {
                System.out.println("Menu item [" + event.getActionCommand() +
                                   "] was pressed.");
              }
            };
        for (int i=0; i < fileItems.length; i++) {
            JMenuItem item = new JMenuItem(fileItems[i], fileShortcuts[i]);
            item.addActionListener(printListener);
            fileMenu.add(item);
        }

        //  Assemble the File menus with keyboard accelerators
        for (int i=0; i < editItems.length; i++) {
            JMenuItem item = new JMenuItem(editItems[i]);
            item.setAccelerator(KeyStroke.getKeyStroke(editShortcuts[i],
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
            item.addActionListener(printListener);
            editMenu.add(item);
        }

        //  Insert a separator in the Edit Menu in Position 1 after "Undo"
        editMenu.insertSeparator(1);

        //  Assemble the submenus of the Other Menu
        JMenuItem item;
        subMenu2.add(item = new JMenuItem("Extra 2"));
        item.addActionListener(printListener);
        subMenu.add(item = new JMenuItem("Extra 1"));
        item.addActionListener(printListener);
        subMenu.add(subMenu2);

        //  Assemble the Other Menu itself
        otherMenu.add(subMenu);
        otherMenu.add(item = new JCheckBoxMenuItem("Check Me"));
        item.addActionListener(printListener);
        otherMenu.addSeparator();
        ButtonGroup buttonGroup = new ButtonGroup();
        otherMenu.add(item = new JRadioButtonMenuItem("Radio 1"));
        item.addActionListener(printListener);
        buttonGroup.add(item);
        otherMenu.add(item = new JRadioButtonMenuItem("Radio 2"));
        item.addActionListener(printListener);
        buttonGroup.add(item);
        otherMenu.addSeparator();
        otherMenu.add(item = new JMenuItem("Potted Plant",
                                    new ImageIcon("image.gif")));
        item.addActionListener(printListener);

        //  Finally, add all the menus to the menu bar
        add(fileMenu);
        add(editMenu);
        add(otherMenu);


    // ovdje sam poceo

        DefaultTableModel dtm = new DefaultTableModel(
                                 new String[][] {
                                   {"1", "2", "3"},
                                   {"4", "5", "6"} },
                                 new String[] {"Names", "In", "Order"});
       SortingColumnModel scm = new SortingColumnModel();
       JTable jt = new JTable(dtm, scm);
       jt.createDefaultColumnsFromModel();

       JScrollPane jsp = new JScrollPane(jt);
       //neweset
       //Add the scroll pane to this panel.
       add(jsp);

    //kraj 
    }



    public static void main(String s[]) {
        JFrame frame = new JFrame("Simple Menu Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setJMenuBar(new IntroExample());
        frame.pack();
        frame.setVisible(true);

    }
}


Koristi code tagove za formatiranje koda ...

[Ovu poruku je menjao veljaradenkovic dana 14.11.2005. u 02:12 GMT+1]
Stane Dolanc: "Bavljenje tehnikom treba da postane svakodnevna potreba coveka.."
 
Odgovor na temu

rj444
Radomir Jakovljevic
Beograd

Član broj: 48212
Poruke: 354
*.rcub.bg.ac.yu.



Profil

icon Re: JMenu i JTable zajedno?13.11.2005. u 22:17 - pre 224 meseci
Malo je tesko citati ovaj kod, ali ako sam dobro shvatio problem, resenje bi trebalo da bude npr. da stavis JTable u BorderLayout.Center, a JMenu dodas u JMenuBar, koji stoji na vrhu ekrana, tako da ce ti JTable biti ispod. Evo dela koda, koji se nalazi u konstruktoru klase koja prosiruje JFrame:

Code:

JMenuBar menuBar=new JMenuBar();
meniBar.add(new JMenu("Neki meni");
this.setJMenuBar(meniBar);

DefaultTableModel dtm = new DefaultTableModel(
  new String[][] {
    {"1", "2", "3"},
    {"4", "5", "6"} 
  },
  new String[] {"Names", "In", "Order"}
);

JTable tabela=new JTable(dtm);

this.getContentPane().add(tabela,BorderLayout.CENTER);



Evo, cisto da steknes uvid.
Pozdrav
 
Odgovor na temu

DusanSukovic
Dušan Šulović
Na krevetu

Član broj: 35637
Poruke: 1371

Sajt: www.MotoBoem.RS


+460 Profil

icon Re: JMenu i JTable zajedno?18.11.2005. u 18:25 - pre 224 meseci
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;


public class MenuTest1 extends JFrame 
{
    private static MenuTest1 me;

    private JMenuBar menu;
    private JMenu file;
    private JMenuItem open, save;

    public MenuTest1() 
    {
        super("Graficki meni");

        open = new JMenuItem ("Otvori", new ImageIcon("openfile.gif"));
        save = new JMenuItem ("Snimi", new ImageIcon("save.gif"));

        file = new JMenu("Fajlovi ");
        file.add(open);
        file.add(save);

        menu = new JMenuBar();
        menu.add(file);

        setJMenuBar(menu);
        setSize(400, 200);
    
        // ovdje sam poceo
        DefaultTableModel dtm = new DefaultTableModel(
        new String[][] {
        {"1", "2", "3"},
        {"4", "5", "6"} 
        },
        new String[] {"Names", "In", "Order"}
        );

        JTable tabela=new JTable(dtm);

        this.getContentPane().add(tabela,BorderLayout.CENTER);


        //kraj 

    
    
    }

    public static final void main(String args[])
    {
        me = new MenuTest1();
        me.show();
    }
}










Evo jedan jednostavniji primjer, uz pomoc tvojeg savjeta. Jednostavno radi :) Puno hvala :)
Stane Dolanc: "Bavljenje tehnikom treba da postane svakodnevna potreba coveka.."
 
Odgovor na temu

[es] :: Java :: JMenu i JTable zajedno?

[ Pregleda: 2177 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

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