logo
down
shadow

Swing - Key Problems (Arrow Keys, Tab, etc.) in GUIs with TextComponents


Swing - Key Problems (Arrow Keys, Tab, etc.) in GUIs with TextComponents

By : Jonas Lindstrøm
Date : November 28 2020, 09:01 AM
will help you The key bindings for the text components take precedence when they have focus. So you need to remove the binding from the text components with code like:
code :
textComponent.getInputMap().put(KeyStroke.getKeyStroke("UP"), "none");


Share : facebook icon twitter icon
Java Swing GUIs on Mac OS X

Java Swing GUIs on Mac OS X


By : Hugthug
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Swing isn't going to give you perfect fidelity with the hosting OS. Sun simply can't devote the considerable resources necessary to do so. My impression is that Swing has gotten much better, but is still going to look out of place by default.
The minimum required to even hope to pass as a Mac app:
How to best position Swing GUIs?

How to best position Swing GUIs?


By : user3443999
Date : March 29 2020, 07:55 AM
will help you To my eye, a GUI in the middle of the screen looks so.. "splash-screen'ish". I keep waiting for them to disappear and the real GUI to appear!
Since Java 1.5 we've had access to Window.setLocationByPlatform(boolean). which..
code :
import javax.swing.*;

class WhereToPutTheGui {

    public static void initGui() {
        for (int ii=1; ii<4; ii++) {
            JFrame f = new JFrame("Frame " + ii);
            f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            String s =
                "os.name: " + System.getProperty("os.name") +
                "\nos.version: " + System.getProperty("os.version");
            f.add(new JTextArea(s,3,28));  // suggest a size
            f.pack();
            // Let the OS handle the positioning!
            f.setLocationByPlatform(true);
            f.setVisible(true);
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater( new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel(
                        UIManager.getSystemLookAndFeelClassName());
                } catch (Exception useDefault) {}
                initGui();
            }
        });
    }
}
Image Map moving using Java Swing- Arrow Keys Terraria Project

Image Map moving using Java Swing- Arrow Keys Terraria Project


By : Morly
Date : March 29 2020, 07:55 AM
help you fix your problem This is the class I 've used to test the program:
the indexes to map/tex have to be carefully selected - I dont know what you want to do with these but the current program moves the map thus answers the question:
code :
class Move {

public Move() {
  JFrame f=new JFrame();
  f.setSize(500, 500);
  Dea d=new Dea();
  f.add(d);
  f.setVisible(true);
  d.requestFocus();
BufferedImage[][] tex=new BufferedImage[16][16];
BufferedImage towie;
int map[][]=new int[30][3000];
int cX=15,cY=15;
class Dea extends JPanel
{
    Dea()
    {

    new ImagesLoader();

//            setBackground(Color.BLACK);
//            setLayout(null);
        for(int i=11;i<30;i++)
        {
            for(int j=0;j<3000;j++)
            {
                map[i][j]=0;
            }
        }
        for(int i=0;i<9;i++)
        {
            for(int j=0;j<3000;j++)
            {
                map[i][j]=815;
            }
        }
        Random r=new Random();
        for(int j=0;j<3000;j++)
        {
            map[9][j]=3;
            int randomNum = r.nextInt(1+ 1);
            map[10][j]=2;
            if(randomNum==0)map[11][j]=2;
            randomNum = r.nextInt(3 + 1);
            if(randomNum==1&&map[11][j]==2)map[12][j]=2;
        }
        addKeyListener(new KeyListener(){
            public void keyReleased(KeyEvent e) { }
            public void keyTyped(KeyEvent e) { }
            public void keyPressed(KeyEvent e)
              {
              System.out.println("keys");
                int c1=cX;
                int c2=cY;
                  int keyCode = e.getKeyCode();
                  char key=e.getKeyChar();
                    switch( keyCode ) { 
                    case KeyEvent.VK_UP:
                        cY++; 
                        break;
                    case KeyEvent.VK_DOWN:
                        cY--;
                        break;
                    case KeyEvent.VK_LEFT:
                        cX--;
                        break;
                    case KeyEvent.VK_RIGHT :
                        cX++;
                        break;
                 }
                    switch( key ) { 
                    case 's':
                    case 'S':
                        cY++; 
                        System.out.println(cX+" "+cY);
                        break;
                    case 'w':
                    case 'W':
                        cY--;
                        System.out.println(cX+" "+cY);
                        break;
                    case 'a':
                    case 'A':
                        cX--;
                        System.out.println(cX+" "+cY);
                        break;
                    case 'd':
                    case 'D':
                        cX++;
                        System.out.println(cX+" "+cY);
                        break;
                 }
//                        if(cX<0||cX>2999)cX=c1;
//                        if(cY<0||cY>30)cY=c2;
                    repaint();
              }
            });
    }
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);

        g.drawImage(towie,0,0, this);
        for(int i=0;i<map.length;i++)
        {
            for(int j=0;j<map[0].length;j++)
            {   
                g.drawImage(tex[map[i][j]/100][map[i][j]/100],cX+j*20,cY+i*20,this);
            }
        }
    }
}
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.drawImage(towie,0,0, this);
        g.drawImage(WholeTexture, cX, cY, this);
    }
How to use BigDecimal in swing GUIs?

How to use BigDecimal in swing GUIs?


By : Isaac Reinaldo
Date : January 02 2021, 06:48 AM
I wish this helpful for you I hate to necro these really old threads on stuff, but my understanding is StackOverflow cries inside every day an answer remains unsolved.
so you can checkout the code here: http://www.java2s.com/Code/Java/Swing-JFC/ABigDecimalobjectcustomformatter.htm
Html - disable page scrolling with arrow keys with out toatlly disabling arrow keys

Html - disable page scrolling with arrow keys with out toatlly disabling arrow keys


By : Elad Noor
Date : March 29 2020, 07:55 AM
it helps some times You should be able to catch the keydown event and prevent the default action (e.g. scrolling), then do whatever else you want with the event. For example:
Related Posts Related Posts :
  • My shape moved but will pause for a while
  • How to solve syntax error in eclipse Mars.1
  • Shibboleth idp configuration for ldap authentication
  • Do something when app starts?
  • Android Runtime Exception font asset not found
  • How to query using objectify in Google App Engine app
  • List value is printing address instead of value
  • StringUtils.isBlank return false for null Strings
  • Sent parameter through PATCH android
  • i am not able to clear the code below given using throwable concept in java
  • How to get System time instead of Server time in java?
  • How to push json data into an arrya object in MONGO DB by java
  • Saving RelationshipEntity not working
  • Error on "instanceOf" when checking a subClass
  • Java - Splitting a image into 4 images
  • "Pinging" a server in Java
  • RoboGuice Proguard CreationException
  • Android Array list returns Null after adding values
  • Jar Executable what am I doing wrong?
  • How do I mitigate Connection leak triggered for connection com.mysql.jdbc.JDBC4Connection@11d08960,
  • How do i iterate values from a 2d array using conditions
  • Hide Button in CustomPagerAdapter
  • Java GC: does it ever make sense to call super.finalize() in a class that only extends Object?
  • 64bit HashMap in Java
  • Hibernate wildcard query on two columns
  • Want to Generate Auto Login Program Using Java
  • Spring security Oauth 2 with ajax login and form login
  • Parse findInBackground doesn't add to global arraylist?
  • Remove random item from ArrayList
  • in SpringMVC getMessage from i18n properties in a function outside the controller
  • How do I add JCheckBox next to each name that has been entered into an arraylist from a JTextField?
  • Return node ID along with complete node
  • InvocationTargetException. Cannot cast class X to class X. When invoked in Scala Imain through spark-submit
  • how to print elements of a 1D array into a N x N box
  • How to map csv file to pojo class in java
  • How, in Java, to encode default vhost %2F in URL/URI so it doesn't get changed to slash and fail to work
  • Tomcat 5.5 https configuration in Windows Server 2008 64bit
  • Enabling FIPS 140-2 compliance mode in MULE ESB
  • How to pass String PackageName to PkgName under parseXML() and run XMLParser class as a new activity when click on list
  • Error while creating spring -hibernate configuration file
  • Hand off control between java threads
  • NoClassDefFoundError: scala/collection/Seq
  • Getting stack overflow error on one machine but not the other on the same code
  • How can I loop AsyncAjaxRequest in GWT?
  • Failed to find provider info for urbanairship.provider
  • Android ListView Adapter Crash issue/Duplicates
  • Displaying Splash screen only once on user preference
  • Loop List<WebElement> doesn't stop despite no more WebElements
  • Check if pattern exists in a String
  • Why the solution for binary search tree validity is not working?
  • Double encrypting 2048 RSA?
  • create junit test for runnable class
  • Unable to read and sort information from a text file in Java
  • My device isn't getting detected in android studio (driver issue)
  • Representing a Graph in Java
  • How to XML mapping using jxls
  • Quick Sort stackoverflow error for large arrays
  • Parsing Apache Tika XML Output returns Unknown Tag
  • java simple UI loop, can't find bug
  • how to use greater than and less than in a single if statement in java
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co