Sie sind auf Seite 1von 3

package paket; import import import import import import import java.awt.BorderLayout; java.awt.Color; java.awt.Component; java.awt.TextArea; java.awt.event.ActionEvent; java.awt.event.

ActionListener; java.util.Vector;

import javax.swing.*; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; public class MainFrame extends JFrame { private static final long serialVersionUID = 1L; public MainFrame() { // General tab JLabel name = new JLabel("Name"); JLabel comment = new JLabel("Comment"); JLabel visibility = new JLabel("Visibility"); String[] visibStringsGen = { "public", "private", "protected" }; JLabel cardinality = new JLabel("Cardinality"); // attributes String[] kolone = { "Name", "Data Type", "Visibility", "Initial Value" }; String[][] redovi = { { "Atribut_1", "String", "-", "Marko" }, { "Atribut_2", "int", "+", "50" }, { "Atribut_3", "boolean", "-", "true" }, { "Atri but_4", "int", "#", "25" } }; //operators String[] kolone_oper = { "Name", "Return Type", "Visibility"}; String[][] redovi_oper = { { "Metoda_1()", "String", "-"}, { "Me toda_2()", "int", "+"}, { "Metoda_3()", "boolean", "-"}, { "Metoda_4()", "int", "#"}}; JTable jt = new JTable(redovi, kolone) { private static final long serialVersionUID = 1L; public boolean isCellEditable(int kolone, int redovi) { return true; } public Component prepareRenderer(TableCellRenderer r, in t redovi, int kolone) { Component c = super.prepareRenderer(r, redovi, k olone); if (redovi % 2 == 0) c.setBackground(Color.WHITE); else c.setBackground(Color.LIGHT_GRAY); if(isCellSelected(redovi, kolone)) c.setBackground(Color.GREEN); return c; }

}; JTable jt1 = new JTable(redovi_oper, kolone_oper) { private static final long serialVersionUID = 1L; public boolean isCellEditable(int kolone_oper, int redov i_oper) { return true; } public Component prepareRenderer(TableCellRenderer r, in t redovi_oper, int kolone_oper) { Component c = super.prepareRenderer(r, redovi_op er, kolone_oper); if (redovi_oper % 2 == 0) c.setBackground(Color.WHITE); else c.setBackground(Color.LIGHT_GRAY); if(isCellSelected(redovi_oper, kolone_oper)) c.setBackground(Color.GREEN); return c; } }; Vector<String> comboOperVis = new Vector<>(); comboOperVis.add("public"); comboOperVis.add("private"); comboOperVis.add("protected"); Vector<String> comboOperRetT = new Vector<>(); comboOperRetT.add("boolean"); comboOperRetT.add("byte"); comboOperRetT.add("char"); comboOperRetT.add("Date"); comboOperRetT.add("double"); comboOperRetT.add("float"); comboOperRetT.add("int"); comboOperRetT.add("long"); comboOperRetT.add("short"); comboOperRetT.add("String"); comboOperRetT.add("void"); Vector<String> comboAttrDatT = new Vector<>(); comboAttrDatT.add("boolean"); comboAttrDatT.add("byte"); comboAttrDatT.add("char"); comboAttrDatT.add("Date"); comboAttrDatT.add("double"); comboAttrDatT.add("float"); comboAttrDatT.add("int"); comboAttrDatT.add("long"); comboAttrDatT.add("short"); comboAttrDatT.add("String"); JComboBox<String> comboboxOpVis = new JComboBox<>(comboOperVis); JComboBox<String> comboboxOpRetT = new JComboBox<>(comboOperRetT ); JComboBox<String> comboboxAttDatT = new JComboBox<>(comboAttrDat

T); JComboBox<String> comboboxAttVis = new JComboBox<>(comboOperVis) ; TableColumn TableColumn TableColumn TableColumn col3 col2 col1 col0 = = = = jt1.getColumnModel().getColumn(2); jt1.getColumnModel().getColumn(1); jt.getColumnModel().getColumn(1); jt.getColumnModel().getColumn(2); DefaultCellEditor(comboboxOpVis)); DefaultCellEditor(comboboxOpRetT)); DefaultCellEditor(comboboxAttDatT)); DefaultCellEditor(comboboxAttVis));

col3.setCellEditor(new col2.setCellEditor(new col1.setCellEditor(new col0.setCellEditor(new

JScrollPane jsp = new JScrollPane(jt); JScrollPane jsp1 = new JScrollPane(jt1); JComboBox visibGenList = new JComboBox(visibStringsGen); visibGenList.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JComboBox combo = (JComboBox) e.getSource(); } }); TextArea t = new TextArea(5, 50); // General Tab, pozivanje JPanel tabgeneral = new JPanel(); tabgeneral.setBackground(Color.WHITE); tabgeneral.add(name); tabgeneral.add(new JTextField("\n", 35)); tabgeneral.add(comment); tabgeneral.add(t); tabgeneral.add(visibility); tabgeneral.add(visibGenList); tabgeneral.add(cardinality); tabgeneral.add(new JTextField(10)); // Attributes Tab, pozivanje JPanel tabattributes = new JPanel(new BorderLayout()); tabattributes.setBackground(Color.WHITE); tabattributes.add(jsp,BorderLayout.CENTER); JPanel taboperations = new JPanel(new BorderLayout()); taboperations.setBackground(Color.WHITE); taboperations.add(jsp1,BorderLayout.CENTER); JTabbedPane tabPanel = new JTabbedPane(JTabbedPane.SCROLL_TAB_LA YOUT); tabPanel.addTab("General", tabgeneral); tabPanel.addTab("Attributes", tabattributes); tabPanel.addTab("Operations", taboperations); add(tabPanel, BorderLayout.CENTER); } }

Das könnte Ihnen auch gefallen