I’m using JPanel with a default FlowLayout layout manager. I think in case the application window was resized and there is not enough width to show all components in JPanel in one row, some components will be moved to another row(s). This assumption is based on the documentation: If the horizontal space in the container is too small to put
Tag: awt
Moving code from ActionListener to main()
PROBLEM: I have following code for the java.awt.Button : I need to move the code inside btn.addActionListener to the public static void main(String[] args), something like below (in pseudo code): RELEVANT INFORMATION : I am aware that there are better solutions for GUI development, but I am restricted to using AWT for UI. I have no power to change the
how to use JTextField to show a negative or positive result using ActionListener on the JTextField itself
My program is supposed to ask a user to write a number in a JTextField and then show the result if the number is negative or positive in another JTextField that is disabled. All of that must be done without a button. Answer In your example you’ve forget to call the method JavaJTextFieldActionListner. I’ve remove it and move the code
How to scale basic drawings?
I would like to have a list of shapes, that appears in my window. Whenever I’m changing the size of the window, I would like to scale all of my drawings. I already prepared classes, that store information about random shapes in a list (rectangles, ovals, etc.). I have no problem with painting them all, but I can’t deal with
JTextField size can’t be changed
} I tried to create a form and a JTextField on it. But the problem is, my location and size doesn’t work. The TextField is filling the whole form. How can I fix it? Answer The size is not “working” due to the default layout (FlowLayout) in your JFrame. This layout doesn’t let you change the size or location of
Java AWT Window doesn’t get repainted
I’ve derived a class from window, but whenever I call setValue() (which calls repaint) it doesn’t get redrawn (the method is called, but nothing changes on the screen). The first value is drawn, which is 0 by default. Here’s the class: Why does it not get repainted properly? Answer From the oracle docs If [the update] method is reimplemented, super.update(g)
Cannot load font in JRE 8
I cannot load a font from an S3 Inputstream in JRE 8. I do not have issue if a system is installed with JRE 7, JDK 7, or even JDK 8. The error that I got is I tried to load the inputstream to a temp file, but it does not help. I also tried to load a font directly
Java and GUI – Where do ActionListeners belong according to MVC pattern?
I’m currently writing a template Java application and somehow, I’m not sure about where the ActionListeners belong if I wanted to cleanly follow the MVC pattern. The example is Swing based, but it’s not about the framework but rather the basic concept of MVC in Java, using any framework to create GUI. I started with an absolutely simple application containing
in java awt or swing, how can I arrange for keyboard input to go wherever the mouse is?
Working on a help system, I’d like each component to offer some help when the the mouse is over it and the “?” key is pressed. Sort of like tooltips, except with much more extensive help – essentially a little web browser is intended to pop up and display text, images or more. What I’m finding is that no matter
How to make a splash screen for GUI?
Hi there I’m new to GUIs in Java and was trying to make a splash screen or an image appear for 3 seconds. Then after that it it will go onto my main program. Does anyone have an ideas how to do this or can link me to any tutorials? So far I have done this but not sure where