system.file.openFile change/increase font size

Is it possible to change/increase font size in system.file.openFile dialog?

On the touch screens with 1920x1080 resolution the directories are very small and it hard to select them with fingers…

Bump… :wave:

Unfortunately, there’s no great way to adjust the size of the components - all the file dialogs in Ignition are instances of the JFileChooser class - and as you can see here, while it’s possible to drill into its components and adjust font sizing, it’s not a trivial thing to do: https://stackoverflow.com/a/18771331

Complicating things further, all scripting events happen on the event dispatch thread, which is interrupted by any modal dialogs in Ignition - including the JFileChooser - so you won’t (easily) be able to access the file chooser through scripting.

This is what I came up with (in button actionPerformed event):

from javax.swing import JList
from javax.swing import JTable
from javax.swing import JFileChooser
from javax.swing import filechooser
from javax.swing import UIManager
from javax.swing import SwingUtilities
#from javax.swing.plaf import FontUIResource
#from java.awt import Font
from java.awt import Component
from java.awt import Container
from java.awt import Dimension
from java.io import FileFilter
from javax.swing.filechooser import FileNameExtensionFilter

#start in this folder
chooser = JFileChooser("C:\\OMG\\BenderOne")
jezik =system.util.getLocale() 
#print "Language=", jezik
#if selected language is Slovenian, set Slovenian text for all labels, buttons, tooltips...
if jezik == "sl":
	UIManager.put("FileChooser.openDialogTitleText", u"Izberi šifro")
	UIManager.put("FileChooser.lookInLabelText", "Poglej v:")
	UIManager.put("FileChooser.saveInLabelText", "Shrani v:")
	UIManager.put("FileChooser.openButtonText", "Izberi mapo")
	UIManager.put("FileChooser.saveButtonText", "Shrani")
	UIManager.put("FileChooser.cancelButtonText", "Prekini")
	UIManager.put("FileChooser.fileNameLabelText", "Ime datoteke:")
	UIManager.put("FileChooser.filesOfTypeLabelText", "Tip datoteke:")
	UIManager.put("FileChooser.openButtonToolTipText", u"Izberi izbrano šifro")
	UIManager.put("FileChooser.saveButtonToolTipText", "Shrani izbrano datoteko")
	UIManager.put("FileChooser.cancelButtonToolTipText","Prekini")
	UIManager.put("FileChooser.fileNameHeaderText","Ime Datoteke:")
	UIManager.put("FileChooser.upFolderToolTipText", u"Nivo višje")
	UIManager.put("FileChooser.homeFolderToolTipText","Namizje")
	UIManager.put("FileChooser.newFolderToolTipText","Naredi novo mapo")
	UIManager.put("FileChooser.listViewButtonToolTipText","List")
	UIManager.put("FileChooser.newFolderButtonText","Naredi novo mapo")
	UIManager.put("FileChooser.renameFileButtonText", "Preimenuj datoteko")
	UIManager.put("FileChooser.deleteFileButtonText", "Izbriši datoteko")
	UIManager.put("FileChooser.filterLabelText", "Tip Datoteke:")
	UIManager.put("FileChooser.detailsViewButtonToolTipText", "Podrobnosti")
	UIManager.put("FileChooser.fileSizeHeaderText","Velikost")
	UIManager.put("FileChooser.fileDateHeaderText", "Spremenjeno")
	SwingUtilities.updateComponentTreeUI(chooser)

#function for changing the font size for everything except icons in top right corner
def setFileChooserFont(comp):
	for x in range (0, len(comp)):
		#recursive
		if isinstance(comp[x],Container): 
			setFileChooserFont(comp[x].getComponents())
		
		try:
			#if isinstance(comp[x],JList) or isinstance(comp[x],JTable):
				comp[x].setFont(comp[x].getFont().deriveFont(comp[x].getFont().getSize() * 2.0))
		except ValueError:
			print ValueError #do nothing
		except AttributeError:
			print AttributeError #do nothing

setFileChooserFont(chooser.getComponents())  

#Allow user to choose only folder
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
chooser.setAcceptAllFileFilterUsed(False)
#chooser.setDialogTitle(u"Izberite Mapo")
# only allow files of .xml extension
restrict = FileNameExtensionFilter("xml files (.xml, .xmls)", ["xml","xmls"])
chooser.addChoosableFileFilter(restrict)
#set size of the FileOpen dialog
chooser.setPreferredSize(Dimension(800,500))
#set text for the OK/Open button
#chooser.setApproveButtonText("Select Dir")
filepath = ""

if chooser.showOpenDialog(event.source.parent) == JFileChooser.APPROVE_OPTION:
	filepath = str(chooser.getSelectedFile())
	event.source.parent.getComponent('Label 2').text = filepath
	event.source.parent.getComponent('Label 3').text = filepath + "\project.xml"

Now you can select with fat fingers also… :point_up_2::grinning:

4 Likes