Heya all,

I'm working on a small 'file browser', where the list of files is printed in a console (for now), but where the user inserts the file's path in a GUI.

My gui is rather simple: one frame and one panel containing a JTextField and a JButton.
I want the JButton to be activated when the user presses enter in the JTextArea (like in any other file browser) to increase useability.

In order to do so, i made the button focusable and the default focus, and that works on windows, but not on linux.
I know the default look and feel for my distro (mint 16), metal, does not activate a button on pressing enter, so i changed that to Motif without any results.

//class responsible for the JPanel and it's content
private JLabel addressLabel;
    private JTextField addressTextField;
    private JButton goButton;
    private JXplorer data;
    //private JLabel iconLabel; // not yet implemented
    private JPanel viewPanel;

    public JXAddressView() {
        viewPanel = new JPanel();

        addressLabel = new JLabel("Address");
        addressTextField = new JTextField(10);
        goButton = new JButton("Go");




//function that builds the JFrame and places the JPanel in it
private void buildGUI() {

        try {               
        } //**snip** some catches

        JFrame frame = new JFrame("JXplorer, The java file exploration utility");



Recommended Answers

Did you try

Jump to Post

All 2 Replies

That works, but it's not a super neat solution, since the panels and their content are being assembled in one class, and the frame is defined in another one (a main() function).

I added a getter for the button so the main class can get it, although this means giving a GUI element to a non-GUI class.
Still, this'll do just fine ;) thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.