5 Replies - 695 Views - Last Post: 25 July 2010 - 11:15 PM Rate Topic: -----

#1 Tapas Bose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 472
  • Joined: 09-December 09

Nevigation Button In Java Swing

Posted 24 July 2010 - 09:56 PM

Hello everybody. I am learning Java Swing and I am trying to build a calculator. I want to add four-way navigation buttons, viz "↓", "→", "↑", "←" in that calculator. Left and right button will be used to move left and right and up arrow to get previous input and down arrow for next input. The output display I made by JTextField. Now how can I do this? I don't know if I able to explain the concept or not. I need a help, just concept. Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Nevigation Button In Java Swing

#2 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: Nevigation Button In Java Swing

Posted 24 July 2010 - 10:09 PM

Well I think it's definitely possible. You just want a concept, like some ideas? I'll see what I can do:

-Good layout for a calculator would be a GridLayout. That's what most people would use when creating a calculator with Swing. Have a button in each section of the grid, and have an actionlistener for the buttons.

-As for the arrows, they would just be buttons as well. I'm not quite sure what you mean by the left and right arrow keys, could you explain a little bit more? For the up arrow key, you're just going to have to save the previous data. An array, or better yet, an ArrayList could be something to consider. And again I'm not quite sure what you're looking for with the Down arrow.

-JTextField seems like a good option to me for displaying the output.


Hopefully this helps! If you want more specifics let me know!
Was This Post Helpful? 1
  • +
  • -

#3 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Nevigation Button In Java Swing

Posted 24 July 2010 - 11:13 PM

the left and right keys should just alter the carat position if I understand you correctly
Was This Post Helpful? 1
  • +
  • -

#4 b0ng01  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 38
  • View blog
  • Posts: 169
  • Joined: 16-July 10

Re: Nevigation Button In Java Swing

Posted 24 July 2010 - 11:40 PM

tampa you are going to have to come up with a way to use setCaratPosition from JTextComponent. JTextField can you the method being a subclass of JTextComponent.

What I would think you want would be something like add a line to your actionlistener for the -> <- buttons call getCaratPosition and then based upon the number -- for <- and ++ for -> on setCaratPosition.

This post has been edited by b0ng01: 24 July 2010 - 11:41 PM

Was This Post Helpful? 1
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Nevigation Button In Java Swing

Posted 25 July 2010 - 01:46 PM

There are there

import javax.swing.plaf.basic.BasicArrowButton;

http://download.orac...rrowButton.html
Was This Post Helpful? 1
  • +
  • -

#6 Tapas Bose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 472
  • Joined: 09-December 09

Re: Nevigation Button In Java Swing

Posted 25 July 2010 - 11:15 PM

Thank you everybody. I took a look on BasicArrowButton.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1