Skip to content

Commit

Permalink
Laf adjustments for FileSelector
Browse files Browse the repository at this point in the history
If CrossPlatformLaF is used than use JFileChooser() in any case, even
when Linux and JRE > 1.6
  • Loading branch information
haniibrahim committed Oct 18, 2018
1 parent c06f1d3 commit cc8c21b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
23 changes: 22 additions & 1 deletion de/haniibrahim/seriallogger/FileSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.File;
import java.io.FilenameFilter;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
Expand Down Expand Up @@ -71,7 +72,8 @@ static String getSaveFilename(Frame frame, String defFilename, String defFilepat
|| System.getProperty("java.version").startsWith("1.1")
|| System.getProperty("java.version").startsWith("1.0")
))
|| (getOS().equals("win"))) {
|| (getOS().equals("win"))
|| (!isNativeLookAndFeel())) {
JFileChooser fd = new JFileChooser(pathName);
fd.setDialogTitle(dialogTitle);
fd.setDialogType(JFileChooser.SAVE_DIALOG);
Expand Down Expand Up @@ -125,4 +127,23 @@ private static String getOS() {
}
return "noarch";
}

/**
* If the underlying platform has a "native" look and feel, and this is an
* implementation of it, return true.
*
* @return true if this look and feel represents the underlying platform look and feel
*/
private static boolean isNativeLookAndFeel() {
// Get current LaF
String lafName = UIManager.getLookAndFeel().getName();
// Workaround for Java and GTK look and feel:
// - UIManager.getLookAndFeel().getName() = "GTK look and feel"
// - UIManager.LookAndFeelInfo.getName() = "GTK+"
if (lafName.equalsIgnoreCase("GTK look and feel")) {
lafName = "GTK+";
}
return !(lafName.equals("Metal") || lafName.equals("Nimbus") || lafName.equals("CDE/Motif"));
}

}
7 changes: 2 additions & 5 deletions de/haniibrahim/seriallogger/Options.form
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,10 @@
</Component>
<Component class="javax.swing.JButton" name="bt_OK">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
<Property name="actionCommand" type="java.lang.String" value="Ok"/>
<Property name="label" type="java.lang.String" value="OK"/>
<Property name="actionCommand" type="java.lang.String" value="OK"/>
</Properties>
<AccessibilityProperties>
<Property name="AccessibleContext.accessibleName" type="java.lang.String" value="Ok"/>
</AccessibilityProperties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bt_OKActionPerformed"/>
</Events>
Expand Down
6 changes: 2 additions & 4 deletions de/haniibrahim/seriallogger/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

bt_OK.setText("OK");
bt_OK.setToolTipText("");
bt_OK.setActionCommand("Ok");
bt_OK.setLabel("OK");
bt_OK.setActionCommand("OK");
bt_OK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bt_OKActionPerformed(evt);
Expand Down Expand Up @@ -215,8 +215,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

bt_OK.getAccessibleContext().setAccessibleName("Ok");

pack();
}// </editor-fold>//GEN-END:initComponents

Expand Down

0 comments on commit cc8c21b

Please sign in to comment.