JFileChooser wybór motywu okna

0

Witam utworzyłem sobie okno dialogowe do zapisu pliku i ku mojemu zdziwieniu motyw okna nie jest taki jak w windowsie 8.1 jak mogę to zmienić?
dialog tworzę tak

	private JFileChooser fileChooser = new JFileChooser();
	private int userSelection=0;
 userSelection = fileChooser.showSaveDialog(this);
		fileChooser.setDialogTitle("Specify a file to save");   
		if (userSelection == JFileChooser.APPROVE_OPTION) {
			File fileToSave = fileChooser.getSelectedFile();
			System.out.println("Save as file: " + fileToSave.getAbsolutePath());
		}

Oraz mam takie pytanie do czego jest potrzebne te dwie linijki bo nie mogę tego rozkminić

 userSelection = fileChooser.showSaveDialog(this); //wiem że showSaveDialog jest odpowiedzialna za pokazanie się okna tylko nie wiem po co userSelection
if (userSelection == JFileChooser.APPROVE_OPTION) // tu nie wiem po to jest APPROVE_OPTION
1

ShowDialog Wyśeiwtla dialog z przyciskami i zwraca wartość klikniętego przycisku.
A co do wyglądu, to jest coś takiego:

 UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
0

APPROVE_OPTION to przycisk zapisz?

1
Masterpc96 napisał(a):

APPROVE_OPTION to przycisk zapisz?

 	APPROVE_SELECTION
Instruction to approve the current selection (same as pressing yes or ok).

https://docs.oracle.com/javase/7/docs/api/javax/swing/JFileChooser.html

Słowem tak:)

0

@Black007: poczytałem o UIManager, w JOptionPane sobie spersonalizowałem czcionkę ale nie mogę zmienić nazw etykiet w JFileChooser
robię to tak w atrybutach klasy definiuję

 	private JFileChooser fileChooser = new JFileChooser();

w konstruktorze tej klasy robię to

 		UIManager.put("FileChooser.saveButtonText","Zapisz");
		UIManager.put("FileChooser.openButtonText","Otwórz");
		UIManager.put("FileChooser.cancelButtonText","Anuluj");
		UIManager.put("FileChooser.updateButtonText","Uaktualnij");
		UIManager.put("FileChooser.helpButtonText","Pomoc");
		UIManager.put("FileChooser.saveButtonToolTipText","Zapisz");
		UIManager.put("FileChooser.openButtonToolTipText","Otwórz");
		UIManager.put("FileChooser.cancelButtonToolTipText","Anuluj");
		UIManager.put("FileChooser.updateButtonToolTipText","Uaktualnij");
		UIManager.put("FileChooser.helpButtonToolTipText","Pomoc");
		fileChooser.setDialogTitle("Zapis");   
		FileFilter pdfFilter =new FileNameExtensionFilter("Pliki *.pdf","pdf");
		fileChooser.addChoosableFileFilter(pdfFilter);
		fileChooser.setFileFilter(pdfFilter);
		fileChooser.setAcceptAllFileFilterUsed(false);

Po kliknięciu w przycisk mam

 userSelection = fileChooser.showSaveDialog(this);
		 if(e.getSource()==print){
				if (userSelection == JFileChooser.APPROVE_OPTION) {
				    File fileToSave = fileChooser.getSelectedFile();
				    System.out.println("Save as file: " + fileToSave.getAbsolutePath());
				}
		 }

Nie wiem czemu to nie działa

EDIT:
działa jak ten kod z UIManager dodam do głównej metody

 	public static void main(String args[]){
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
				| UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		UIManager.put("FileChooser.saveInLabelText", "Zapisz w ");
		  UIManager.put("FileChooser.saveButtonText","Zapisz");
		  UIManager.put("FileChooser.openButtonText","Otwórz");
		  UIManager.put("FileChooser.cancelButtonText","Anuluj");
		  UIManager.put("FileChooser.updateButtonText","Uaktualnij");
		  UIManager.put("FileChooser.helpButtonText","Pomoc");
		  UIManager.put("FileChooser.saveButtonToolTipText","Zapisz");
		  UIManager.put("FileChooser.openButtonToolTipText","Otwórz");
		  UIManager.put("FileChooser.cancelButtonToolTipText","Anuluj");
		  UIManager.put("FileChooser.updateButtonToolTipText","Uaktualnij");
		  UIManager.put("FileChooser.helpButtonToolTipText","Pomoc");
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				new MyFrame();
			}
		});
	}

Czytałem że należy UImanager dodawać do pierwszych linijek konstruktora klasy w której mają być używane

0

Tak, na szybko, to spróbuj w tym konstruktorze po ustawieniu UiManager.put() wywołać SwingUtilities.updateComponentTreeUI(this).
W dokumentacji jest napisane, ze to powinno odświeżyć component wraz ze wszystkimi jego elementami. Tylko głowy nie dam sobie uciąć, że z this zadziała.

1 użytkowników online, w tym zalogowanych: 0, gości: 1