Witam
Chce uzyc opcji isCellEditable(int row, int column) aby zablokowac opcje edycji tekstu (ma byc taka mozliwosc ale dopiero po wybraniu opcji edytuj). Na poczatek chce zablokowac edycje i mam problem z zaimplementowaniem tego do kodu, problem jest tez taki ze w przyszlosci dane maja byc pobierane z pliku/plikow, wiec nie moze byc to stala wartosc a musi byc zmienna w zaleznosci od ilosci danych .Gdyby ktos byl w stanie zerknac i mi jakos pomoc to byl bym wdzieczny. (wiersze 90-96).
Ps. W tym momecie odpala mi program ale nie pokazuje w ogole tabeli a w konsoli wyswietla sie
(https://4programmers.net/uploads/attachment/5e/5e90ad1ccff67.pngt/uploads/attachment/5e/5e90ad1ccff67.png)
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuBar;
import javax.swing.table.DefaultTableModel;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class GUI extends JFrame {
JMenuItem Wczytaj, Zapisz, glosnosc;
int volume;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
public static void createAndShowGUI() {
JMenu menuOption, menuSetting, menuSorting;
JPanel panel = new JPanel();
JFrame main = new JFrame();
main.setTitle("music player");
main.setBounds(450, 100, 1024, 768);
main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
main.setResizable(false);
main.setLayout(null);
main.setVisible(true);
JFrame Funkcje = new JFrame();
Funkcje.setBounds(450, 618, 220, 105);
Funkcje.setResizable(false);
Funkcje.setVisible(true);
Funkcje.setLayout(null);
JButton Play = new JButton("|>");
Play.setBounds(100, 45, 50, 20);
Funkcje.add(Play);
JButton rollback = new JButton("<<");
rollback.setBounds(0, 45, 50, 20);
Funkcje.add(rollback);
JButton Rewind = new JButton(">>");
Rewind.setBounds(150, 45, 50, 20);
Funkcje.add(Rewind);
JButton Pause = new JButton("||");
Pause.setBounds(50, 45, 50, 20);
Funkcje.add(Pause);
JSlider Volume = new JSlider(0, 100, 0);
Volume.setBounds(0, 0, 200, 45);
Funkcje.add(Volume);
JMenuBar menuBar = new JMenuBar();
menuOption = new JMenu("Menu");
JMenuItem Wczytaj = new JMenuItem("Wczytaj");
JMenuItem Zapisz = new JMenuItem("Zapisz");
menuOption.add(Wczytaj);
menuOption.addSeparator();
menuOption.add(Zapisz);
menuSetting = new JMenu("Setting");
JMenuItem glosnosc = new JMenuItem("volume");
menuSetting.add(glosnosc);
menuSorting = new JMenu("Sorting");
JRadioButtonMenuItem alfabetycznie = new JRadioButtonMenuItem("Alfabetycznie");
JRadioButtonMenuItem rokwydania = new JRadioButtonMenuItem("Dacie wydania");
JRadioButtonMenuItem dlugosc = new JRadioButtonMenuItem("Dlugości");
menuSorting.add(alfabetycznie);
menuSorting.addSeparator();
menuSorting.add(rokwydania);
menuSorting.addSeparator();
menuSorting.add(dlugosc);
main.setJMenuBar(menuBar);
menuBar.add(menuOption);
menuBar.add(menuSetting);
menuBar.add(menuSorting);
Object[][] data = {{"placki", "5,0", "tadeusz", "2019", "pop"}, {"makaron", "3,25", "cezik", "2015", "rap"}};
String[] Column = {"Tytuł", "Czas trwania", "Twórca", "Data premiery", "gatunek"};
JTable jt = new JTable(data, Column);
JScrollPane sp = new JScrollPane(jt);
sp.setBounds(0, 0, 1010, 708);
int rows = jt.getRowCount();
int column = jt.getColumnCount();
jt.isCellEditable(rows, column);
main.add(sp);
}
public void actionPerformed(ActionEvent e) {
Object z = e.getSource();
if (z == Wczytaj) {
JFileChooser wczytaj = new JFileChooser();
if (wczytaj.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
}
} else if (z == Zapisz) {
JFileChooser zapisz = new JFileChooser();
if (zapisz.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
File plik = zapisz.getSelectedFile();
}
}
}
}
- screenshot-20200410192950.png (62 KB) - ściągnięć: 33
- screenshot-20200410193004.png (62 KB) - ściągnięć: 36