jframe

java: How to add Transparent Gradient Background to JFrame

拥有回忆 提交于 2019-12-06 14:45:53
问题 java: I want to use the Gradient style Transparent Background to JFrame. On the top the transparency should be 100% but when going down it should go on decreasing and at the bottom it should be 20% I know i can use the images already having such effect but i want to provide the themes facility and allowing user to use their favorite images but allow transparency at the run time. 回答1: Sun added support for translucent backgrounds to java in 6u10 but it is not formally described in the API. In

Swing - setResizable(true) make JFrame title bar higher and window size smaller

夙愿已清 提交于 2019-12-06 14:08:21
问题 In case someone marks it as duplicate, I will do it myself: we have a very relative question long before: Java setResizable(false) changes the window size (swing) And none solution works for me. Here is my SSCCE: import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import javax.swing.BorderFactory; import javax.swing.JButton; import javax

Why I cannot add a JPanel to JFrame?

纵饮孤独 提交于 2019-12-06 13:16:55
Here is the code: import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import java.awt.event.*; import java.awt.*; public class GameWindow { private String[] players; private JFrame frame; // Constructor. public GameWindow(String[] players) { this.players = players; } // Start the window in the EDT. public void start() { SwingUtilities.invokeLater(new Runnable() { public void run() { showWindow(); controller.start(); } }); } // Defines the general properties of and starts the window. public void showWindow() { frame = new JFrame(

How to override windowsClosing event in JFrame

南楼画角 提交于 2019-12-06 12:22:00
问题 i'm developing a JFrame which has a button to show another JFrame. On the second JFrame i want to override WindowsClosing event to hide this frame but not close all the application. So i do like this: On second JFrame addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); private void formWindowClosing(java.awt.event.WindowEvent evt) { this.dispose(); } but application still close when i click x button

JPanel not displaying in JFrame - Java

让人想犯罪 __ 提交于 2019-12-06 11:39:27
问题 Server is a class I made that extends JFrame. Server serverApp = new Server(TITLE, WIDTH, HEIGHT, true, false); I've effectively removed almost all the other code but the problem still remains! c = getContentPane(); c.setLayout(new BorderLayout()); //Components /***AHHHHH***/ lblEnterMessage = new JLabel("Enter Message "); txtEnterMessage = new JTextField(50); txtEnterMessage.addActionListener(this); btnSend = new JButton("Send"); btnSend.addActionListener(this); taDisplay = new JTextArea(

problem in adding image to JFrame

佐手、 提交于 2019-12-06 11:13:52
I'm having problems in adding a picture into JFrame, something is missing probebly or written wrong. here are the classes: main class: public class Tester { public static void main(String args[]) { BorderLayoutFrame borderLayoutFrame = new BorderLayoutFrame(); borderLayoutFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); borderLayoutFrame.setSize(600,600); borderLayoutFrame.setVisible(true); } } public class BorderLayoutFrame extends JFrame implements ActionListener { private JButton buttons[]; // array of buttons to hide portions private final String names[] = { "North", "South", "East",

Two Different Panels in One Frame - Java

拜拜、爱过 提交于 2019-12-06 09:43:20
问题 I have a question. I have one main frame, and to the left i have a sidebar with menus. My question is, is it possible to make another panel within the main frame, so that if menu1 is clicked, the related contents should be displayed to the second half of the main frame, and when other menus are pressed then obviously the relevant stuff according to what is selected. its a bit hard to explain, sorry. Has anyone got an idea, whether that is possible in Java with Eclipse? 回答1: yes this's pretty

managing parent frame from child frame on java swing

若如初见. 提交于 2019-12-06 09:20:55
问题 I have a jframe (parent) which creates an input frame (child) where I get some parameter. In the "child" frame I have "ok" and "cancel" buttons. When "ok" button is pressed, the parent frame needs to be updated with new data. What is the best way to do that?? 回答1: Pass in a reference to the parent frame when you create (or display) the child frame. This will require an overloaded constructor or display method. Once the child has the reference, it can of course call any method that the parent

Disable drag of JFrame

雨燕双飞 提交于 2019-12-06 09:04:31
I want to ask how to make frame can not drag when the application is running? And then how to disable maximize, minimize button (title bar)? I'm using JFrame . Just add the below line it removes the window decorations like close maximise and minimise(titlebar). This itself disables the dragging only with mouse events. frame.setUndecorated(true); hoang nguyen You can use a JWindow instead of a JFrame . There is no title bar, so the user won't be able to move it. setResizable(false); setUndecorated(true); getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); 来源: https://stackoverflow

How can I add \\t spacing in a String that belongs to a DefaultListModel which belongs to a JLIst?

孤街醉人 提交于 2019-12-06 08:21:15
I've heard somewhere that it's not possible to add \t (tab) spacing in GUIs, is this true? Does \t only apply to System...println etc? In any case, how would I be able to cause tabbed spacing? Current Code and Preview of JList Code | String.format("%s \t %s \t %s", string1, string2, string3); Preview | string1 string2 string3 Expected Preview string1 string2 string3 Other tests I did try adding a space String between e.g. String space = " "; String.format("%s %s %s %s %s", string1, space, string2, space, string3); But the spacing isn't consistent with multiple JList models. Got a solution to