jframe

JFrame add scrollbar

杀马特。学长 韩版系。学妹 提交于 2020-01-24 11:59:05
问题 I've tried a few tutorials and had a look at other answers but it still doesn't seem to help me, I want to add a scrollbar to this console-like JTextArea, and keep the property whereby each new line of text will push the rest up. This is what it looks like currently: And the code: Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int width = 600; int height = 400; JFrame frame = new JFrame("ChanDown"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel

JFrame.setExtendedState doesn't actually maximise

别来无恙 提交于 2020-01-23 19:42:10
问题 public static void main(String args[]){ JFrame frame = new JFrame(); frame.setExtendedState(JFrame.MAXIMISED_BOTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } I've used this code to maximise a JFrame, but instead of actually maximising the frame, it just sets the window size to that of the screen, without actually changing the state, so clicking the maximize button doesn't actually downscale it again. Am I using the wrong command or something? 回答1: You

How to properly hide a JFrame

[亡魂溺海] 提交于 2020-01-23 06:25:22
问题 I have a very simple JFrame window that contains one button: No . In the main function I set setVisible(true); my JFrame and in the No button listener I want to close the window so I set the visibility to false: setVisible(false); and after that I do System.exit(0); in order to prevent possible memory leaks when running the program many times. I have two questions: Do I really need to System.exit(0); in the above case? If I have this JFrame as a popup window, I can't really use System.exit(0)

Java GUI Swing Model Explanation

巧了我就是萌 提交于 2020-01-22 05:27:12
问题 I've been working with Swing for a while now but the whole model/structure of JFrame s, paint() , super , etc is all murky in my mind. I need a clear explanation or link that will explain how the whole GUI system is organized. 回答1: The same happened to me. Actually to this day I don't quite get 100% how all it works. Swing is a very flexible framework - perhaps too flexible. With flexibility comes a lot of abstraction and with abstraction comes confusion. :) I've found the following articles

Java GUI Swing Model Explanation

主宰稳场 提交于 2020-01-22 05:26:17
问题 I've been working with Swing for a while now but the whole model/structure of JFrame s, paint() , super , etc is all murky in my mind. I need a clear explanation or link that will explain how the whole GUI system is organized. 回答1: The same happened to me. Actually to this day I don't quite get 100% how all it works. Swing is a very flexible framework - perhaps too flexible. With flexibility comes a lot of abstraction and with abstraction comes confusion. :) I've found the following articles

Trouble having 2D Array of buttons click themselves randomly using the computer and not user inputs [duplicate]

跟風遠走 提交于 2020-01-22 03:44:25
问题 This question already has answers here : doClick(), and Simon: All buttons will unpress at the same time instead of individually (1 answer) Java Swing blinking button sequence (2 answers) Java game, restart on user command when game is over (1 answer) Issues with GridLayout (1 answer) Closed 3 days ago . I'm currently making a 2D array of buttons (3x3) and need some help having the program click a random button by itself. I'm currently attempting to use doClick() without any success. I need

DragTabFrame closing inconsistently

扶醉桌前 提交于 2020-01-21 07:20:48
问题 The code below is supposed to work a little like the Multi-Document Interface (MDI) you might see in a browser like FF, IE or Chrome. It presents 'documents' (a black buffered image as spacer) in a tabbed pane such that they can be dragged from the pane into a new (or existing) window by user choice. But it has had issues with closing frames once they have no more tabs, as well as closing the JVM when there are no further visible windows. I think I fixed them by checking with a Timer in the

What is the proper way to swap out an existing JPanel in a JFrame with another?

徘徊边缘 提交于 2020-01-20 08:53:08
问题 I'm building a program that requires swapping out the current, visible JPanel with another. Unfortunately there seems to be multiple to go about this and all of my attempts have ended in failure. I can successfully get the first JPanel to appear in my JFrame, but swapping JPanels results in a blank JFrame. My Main JFrame: public class ShellFrame { static CardLayout cl = new CardLayout(); //handles panel switching static JFrame frame; //init swing on EDT static MainMenu mm; static Panel2 p2;

Why JMenuBar is not place in the JFrame content pane, but JToolbar place in the content pane

会有一股神秘感。 提交于 2020-01-19 17:58:27
问题 Why JMenuBar is not place in the content pane?is there any reason or effects when make a java gui program especially when using jframe? Thanks 回答1: As stated in Using Top-Level Containers article, the manu bar is managed by the Root Pane: Each top-level container relies on a reclusive intermediate container called the root pane. The root pane manages the content pane and the menu bar, along with a couple of other containers. You generally don't need to know about root panes to use Swing

Why JMenuBar is not place in the JFrame content pane, but JToolbar place in the content pane

情到浓时终转凉″ 提交于 2020-01-19 17:58:27
问题 Why JMenuBar is not place in the content pane?is there any reason or effects when make a java gui program especially when using jframe? Thanks 回答1: As stated in Using Top-Level Containers article, the manu bar is managed by the Root Pane: Each top-level container relies on a reclusive intermediate container called the root pane. The root pane manages the content pane and the menu bar, along with a couple of other containers. You generally don't need to know about root panes to use Swing