0

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 :

enter image description here

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);
}
}
789
  • 718
  • 1
  • 10
  • 30
  • You've shown us what you've tried, but not when it's called. Typically, you would set the L&F before any components are created, but we can't see that with just this small snippet. Please post a [Minimal, Complete, Verifiable Example](http://stackoverflow.com/help/mcve) that demonstrates the problem. – splungebob Oct 17 '14 at 13:26
  • Swing does not use native controls, it emulates them. You'll need to use a different UI library to get true native controls. – John Kugelman Oct 17 '14 at 13:30
  • 2
    If you want your Swing application to look like a native application you need to use the **System** Look and Feel not the **Cross Platform** Look and Feel. `UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());` –  Oct 17 '14 at 13:30
  • Also, for customizations, see this post for the general idea: http://stackoverflow.com/a/8209911/1438660 – splungebob Oct 17 '14 at 13:30
  • thanks @a_horse_with_no_name !! it works! and thanks `@splungebob`, I will look in to that. – 789 Oct 17 '14 at 13:38

0 Answers0