Java applications theme
Aere Greenway
Aere at Dvorak-Keyboards.com
Tue Jun 25 22:20:48 UTC 2013
On 06/25/2013 02:31 PM, Pierre Gobin wrote:
> Le 25/06/2013 21:55, Aere Greenway a écrit :
>> On 06/25/2013 01:23 PM, Pierre Gobin wrote:
>>> Hi all,
>>>
>>> I have a problem with Java applications in Lubuntu. When I use them,
>>> they use the default Java theme (metal). How make them using Lubuntu
>>> default theme (Lubuntu Box) ?
>>>
>>> I tried to modify the swing.properties as indicated here [1], but it
>>> didn't change anything. Any idea ?
>>>
>>> Kind regards,
>>> Pierre GOBIN
>>>
>>> [1]
>>> http://askubuntu.com/questions/21886/how-can-i-get-a-java-apps-to-use-the-gtk-theme
>>>
>> Pierre:
>>
>> I have overcome that default by using the GTK+ look-and-feel, which
>> seems to be available in all of the Linux distributions I have tested.
>>
>> After doing that, my Java application uses the selected theme, as
>> well as color customization.
>>
>
> Thanks. But exactly, I fail to use GTK+ look-and-feel. What do I need
> to do to use it ?
>
Pierre:
Unfortunately, it's not simple (I wish it were).
I have cut-and-pasted some code snippets which hopefully can give you an
idea of how to do it. The code comes from a Java Swing application of mine.
--------------------------------------------------------------------------------------------------------------------------------------
// This code runs when the main dialog is shown.
// Set up the look-and-feel.
jComboBoxF1LookAndFeel.removeAllItems() ;
String systemPLAF = UIManager.getSystemLookAndFeelClassName() ;
jComboBoxF1LookAndFeel.addItem("cross-platform") ;
lafClassNames.add(UIManager.getCrossPlatformLookAndFeelClassName()) ;
jComboBoxF1LookAndFeel.addItem("system") ;
lafClassNames.add(systemPLAF) ;
UIManager.LookAndFeelInfo [] installed =
UIManager.getInstalledLookAndFeels() ;
for (int lfIndex = 0 ; lfIndex < installed.length ; lfIndex++)
{ // For each installed look-and-feel:
jComboBoxF1LookAndFeel.addItem(installed[lfIndex].getName()) ;
lafClassNames.add(installed[lfIndex].getClassName()) ;
}
LookAndFeel [] aux = UIManager.getAuxiliaryLookAndFeels() ;
if (aux != null)
{
for (int alfIndex = 0 ; alfIndex < aux.length ; alfIndex++)
{ // For each auxilliary look-and-feel:
jComboBoxF1LookAndFeel.addItem(aux[alfIndex].getName()) ;
lafClassNames.add(installed[alfIndex].getClassName()) ;
}
}
jComboBoxF1LookAndFeel.setSelectedItem(DEFAULT_LOOK_AND_FEEL) ;
lafIndex = jComboBoxF1LookAndFeel.getSelectedIndex() ;
--------------------------------------------------------------------------------------------------------------------------------------
// This is the code for processing state-changes of the LookAndFeel
combo-box:
private void jComboBoxF1LookAndFeelItemStateChanged(ItemEvent evt)
{
System.out.println("jComboBoxF1LookAndFeel.itemStateChanged,
event="+evt);
configValues.jComboBoxF1LookAndFeelValue = (String)
jComboBoxF1LookAndFeel.getSelectedItem() ;
lafIndex = jComboBoxF1LookAndFeel.getSelectedIndex() ;
changeLookAndFeel() ;
}
--------------------------------------------------------------------------------------------------------------------------------------
// This is the method that changes the look-and-feel
private void changeLookAndFeel()
{
if (isInitialized && lafIndex >= 0)
{ // We're initialized, and a Look-and-Feel has been selected.
try
{
String selectedLafClass = (String)
lafClassNames.get(lafIndex) ;
UIManager.setLookAndFeel(selectedLafClass) ;
SwingUtilities.updateComponentTreeUI(metricsDlg.jPanelMain) ;
SwingUtilities.updateComponentTreeUI(jTabbedPanelFunctionKeys.getParent()) ;
}
catch (Exception e)
{
String exceptionType = e.toString() ;
int to = exceptionType.indexOf(":") ;
if (to > 0)
exceptionType = exceptionType.substring(0, to) ;
String message = "Unable to use " +
jComboBoxF1LookAndFeel.getSelectedItem() +
" look-and-feel.\nClass=" +
lafClassNames.get(lafIndex) + "\n" +
exceptionType ;
int result = JOptionPane.showConfirmDialog(null, message,
"Set Look-and-Feel", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.ERROR_MESSAGE) ;
if (result == JOptionPane.CANCEL_OPTION)
{
System.exit(1) ;
}
}
}
}
--
Sincerely,
Aere
More information about the Lubuntu-users
mailing list