I made a small JDialog
that contains a JScrollPane and few other components, on Windows 8.1 OS.
The problem is, that the scrollPane's scrolls are a little weird... not the native Windows 8.1 scrolls :
I tried using the look and feel
function as fallows:
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
// Handle exception
}
and that didn't help at all.
So, am I using it just wrong, or is there any other way to use the native OS scrolls?
Also, if anyone could explain how to customize the scrolls (like the arrow pictures, or customize the track and knob) I would be grateful.
EDIT This is the code of the mentioned JDialog that iis having the problem:
package home;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.LookAndFeel;
import javax.swing.ScrollPaneLayout;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;
import net.miginfocom.swing.MigLayout;
import javax.swing.JLabel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Label;
import java.awt.Font;
import java.awt.List;
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.awt.Button;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.WindowFocusListener;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class ErrorDialog extends JDialog {
JDialog d = this;
Clip errorSoundClip = null;
/**
*
*/
private static final long serialVersionUID = -6060765607593894158L;
/**
* Launch the application.
*/
/**
* Create the dialog.
*/
public ErrorDialog(final JFrame parent,final String errors) {
parent.setEnabled(false);
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
// Handle exception
}
addWindowFocusListener(new WindowFocusListener() {
public void windowGainedFocus(WindowEvent e) {
}
public void windowLostFocus(WindowEvent e) {
System.out.println("alert!!");
d.requestFocus();
}
});
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(new File("src\\home\\sounds\\Sad Trombone Sound Effect - Wah Wah Wah FAIL Sound - Fail Horns.wav").getAbsoluteFile());
} catch (UnsupportedAudioFileException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
errorSoundClip = AudioSystem.getClip();
} catch (LineUnavailableException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
errorSoundClip.open(audioInputStream);
} catch (LineUnavailableException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
errorSoundClip.start();
}
@Override
public void windowClosed(WindowEvent e) {
parent.setEnabled(true);
errorSoundClip.stop();
}
});
setBounds(new Rectangle(0, 0, 480, 220));
JScrollPane scrollPane = new JScrollPane();
getContentPane().add(scrollPane, BorderLayout.CENTER);
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(450, 150));
panel.setAutoscrolls(true);
scrollPane.setViewportView(panel);
panel.setLayout(new MigLayout("", "[100.00%,grow]", "[][grow][43.93%][]"));
Label label = new Label("The operation could have not beed completed. Reasons for failling:");
label.setForeground(Color.RED);
label.setFont(new Font("Dialog", Font.PLAIN, 15));
panel.add(label, "cell 0 0,alignx center");
List list = new List();
panel.add(list, "cell 0 2,grow");
JButton btnNewButton = new JButton("Close");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
d.dispose();
}
});
panel.add(btnNewButton, "cell 0 3,growx");
list.add(errors);
}
}