jframe

How to make a button that, when clicked, opens the %appdata% directory?

若如初见. 提交于 2019-11-28 05:51:02
问题 I have made a button, but I don't now how to make it open a specific directory like %appdata% when the button is clicked on. Here is the code -> //---- button4 ---- button4.setText("Texture Packs"); button4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileChooser=new JFileChooser("%appdata%"); int status = fileChooser.showOpenDialog(this); fileChooser.setMultiSelectionEnabled(false); if(status == JFileChooser.APPROVE_OPTION) { File file =

How do I put graphics on a JPanel?

谁说胖子不能爱 提交于 2019-11-28 04:55:25
问题 I am having a problem adding graphics to a JPanel. If I change the line from panel.add(new graphics()); to frame.add(new graphics()); and do not add the JPanel to the JFrame, the black rectangle appears on the JFrame. I just cannot get the black rectangle to appear on the JPannel and was wondering if someone could help me with this. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Catch{ public class graphics extends JComponent{ public void paintComponent

JFrame inside another JFrame

为君一笑 提交于 2019-11-28 04:31:36
问题 I have a game of chess. I have written 3 classes. 1st if for game. (chessboard, pieces, and so on) And another one is for menu. (buttons like new, open, set time) Both of them use JFrame. I would like to put both classes mentioned above into the 3rd class. For example the Game window would be on the left, and the menu on the right. The third class would also show the whole app by JFrame. How to do that? 回答1: You can't put one JFrame inside another. You have a couple of design choices here.

How to pass a variable value from one JFrame to Another JFrame in Netbeans

ぐ巨炮叔叔 提交于 2019-11-28 04:08:10
问题 I have two JFrames login.java and account.java I need to get the username from the login.java page and put it in a variable in the account.java JFrame . How can I do this in the Java NetBeans using the Swing? 回答1: Instead of Using JFrames for passing values between different forms you can use CardLayout which will persist your data which you have entered in the previous form. All you have to do is Create a JFrameForm and add panels to it. 回答2: You can use getter and setter methods... Set the

setMaximumSize not working in java

拟墨画扇 提交于 2019-11-28 03:50:39
问题 I hava a java program with a JFrame I am using absolute positioning here is my main function public static void main(String[] args) { ape Ape = new ape(); Ape.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Ape.setSize(1000,1000); Ape.setMinimumSize(new Dimension(1000,1000)); Ape.setMaximumSize(new Dimension(1000,1000)); Ape.setVisible(true); } When I run the program I try to resize it and make the window smaller but I can't when I try to make the window bigger it works fine I basicly skips

How do you make key binding for a JFrame no matter what JComponent is in focus?

十年热恋 提交于 2019-11-28 03:46:54
问题 How do we make key bindings for a JFrame regardless of what's in focus in the frame? I already looked at this question: How do you make key bindings for a java.awt.Frame? I tried setting the input map for the root pane of the JFrame, but it doesn't work when the focus is on a JTextArea even though editable is false. What's the easiest way to make key bindings work across an entire JFrame? 回答1: I tried setting the input map for the root pane of the JFrame, but it doesn't work when the focus is

setSize() doesn't work for JFrame

*爱你&永不变心* 提交于 2019-11-28 03:16:16
问题 import javax.swing.JFrame; import javax.swing.SwingUtilities; class Demo { JFrame jf; Demo() { jf=new JFrame("Demo"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(5000,5000); jf.setVisible(true); System.out.println(jf.getSize()); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new Demo(); } }); } } I use jf.setSize(5000, 5000) for JFrame but after that getSize returns other size: java.awt.Dimension[width

Java, JFrame: getWidth() returns 0

╄→尐↘猪︶ㄣ 提交于 2019-11-28 03:11:16
问题 setExtendedState(getExtendedState()|JFrame.MAXIMIZED_BOTH); setResizable(false); setUndecorated(true); System.out.println("--------> "+getContentPane().getWidth()); //----> 0 why is this happening? I'm trying to determine the size of a JFrame. I've searched on google and checked the documentation and I still don't know why it won't work It works fine on about any other control I try it on EDIT: frame.getWidth() works when called outside of the class (that extends JFrame) still, if I replace

Can I create a BufferedImage from a JPanel without rendering in a JFrame?

99封情书 提交于 2019-11-28 03:03:19
问题 Is it possible to create a BufferedImage from a JPanel without first rendering it in a JFrame? I've searched everywhere I can think of and cannot find an answer. Can anyone help? Here is some sample code. If I don't un-comment the JFrame code, my BufferedImage is blank. test(){ // JFrame frame = new JFrame(); JPanel panel = new JPanel(); Dimension dim = new Dimension(50,50); panel.setMinimumSize(dim); panel.setMaximumSize(dim); panel.setPreferredSize(dim); JLabel label = new JLabel("hello");

How to center align the title in a JFrame?

南笙酒味 提交于 2019-11-28 02:58:19
问题 I have a JFrame with a Title . I want center align the title , so that it appears in the middle of the JFrame's title . Thanks. 回答1: Consider leaving the title left-justified...but...this will get you near the center. For resizable frames, you need to rewrite the title on resize. JFrame t = new JFrame(); t.setSize(600,300); t.setFont(new Font("System", Font.PLAIN, 14)); Font f = t.getFont(); FontMetrics fm = t.getFontMetrics(f); int x = fm.stringWidth("Hello Center"); int y = fm.stringWidth("