jpanel

Layout Manager for lining up variably-sized components vertically and horizontally

寵の児 提交于 2019-12-12 04:21:30
问题 I'm trying to make a fairly basic panel for adding/editing users in a database. To make this happen, I want to have a number of labels for different fields on the left, and the appropriate controls for that field on the right. (So, the left might say something like "Username", "User Type", "Expiration Date", etc, and the associated right-hand side would have a text panel, a drop down, and a calendar widget.) The problem I'm running into is that I want these to both line up horizontally (a

Get index number of a certain container in arraylist of jpanels

陌路散爱 提交于 2019-12-12 04:15:36
问题 I was wondering if there was a method for ArrayLists, similar to indexOf(), that could tell me what the element number of a particular container was. Say I had an ArrayList that held Strings: ArrayList<String> stringHolder = new ArrayList<>(); If I were looking for the element number of the String that contained "example", I would just call: stringHolder.indexOf("example"); to find my answer. How can you do this wth JPanels? Especially if all of the containers are virtually the same. I need

JSpinner AutoSelect not working when using FocusTraversalPolicy

天涯浪子 提交于 2019-12-12 03:57:40
问题 While restructuring my application, I began to add FocusTraversalPolicies to each of my Applications JPanels. During that I noticed something odd. Using @MadProgrammers implementation of a FocusListener for JSpinners to autoselect the text of it (can be found here), I wanted to be able to tab through a series of JSpinners. As an MCVE (had to be that long to show the problem and include everything needed) I made up a smaller program showing the problem I am facing: import java.awt.Component;

Printing multiple components

青春壹個敷衍的年華 提交于 2019-12-12 03:55:59
问题 I am trying to send a JTable and a JPanel to the printer in a single print job like this : PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(OrientationRequested.LANDSCAPE); MessageFormat header = new MessageFormat("Page {0}"); Printable p1 = table.getPrintable(JTable.PrintMode.FIT_WIDTH, header, null); PageFormat pf = new PageFormat(); Printable p2 = new ComponentPrinter().returnIt(jPanel1); Book book = new Book(); book.append(p1, pf); book.append(p2, pf);

Having issues with displays

淺唱寂寞╮ 提交于 2019-12-12 03:53:53
问题 I have a custom image of a sunset as my background in a Java program. It is a JFrame with a JPanel and the JPanel houses the sunset background. Is there no way I can draw or paint the images of my sprite sheet on top of the background? Will I have to use basic colors in which I can pick inside the program such as background(Color.BLACK);? I wanted to use the custom image as my background and draw on top o the background as if it was the Canvas or Panel I am planning to use. I want my game to

Focus on component when a panel is loaded

懵懂的女人 提交于 2019-12-12 03:44:53
问题 I have a frame, where i load a panel into. It works fine, but nothing has focus when it loads. Pressing tab doesn't help. I have to use the mouse to press a textfield. I've tried: jtextfield1.requestFocus(); and jtextfiel1.requestFocusInWindow(); But it doesn't work. What am I doing wrong? The constructor in the JPanel : public OpretOpdater(BrugerHandler brugerHandler, ReklamationHandler reklamationsHandler) { initComponents(); jTextFieldOrdnr.requestFocusInWindow(); this.brugerHandler =

Java KeyListener not responding after switching JPanels

对着背影说爱祢 提交于 2019-12-12 03:40:17
问题 I got a problem with the KeyListener not responding(due to not gaining focus) when I switch between JPanels. I have Google'd this and know that to fix this problem I need to use KeyBindings, but I don't like KeyBindings. So I was wondering, is there any other way? Here is the init code of the JPanel that has an unresponsive KeyListener: public void init() { setFocusable(true); requestFocusInWindow(); requestFocus(); addMouseListener(new MouseInput()); addMouseMotionListener(new MouseInput());

Performing two actions in order

半世苍凉 提交于 2019-12-12 03:29:28
问题 I am creating a swing application. It consists of calling a function with some time consuming code. The problem is the "time consuming code" , it is called before the Label's text is set. I want the label to be set before it goes onto the next line. Why does this occour ? myFunction() { myLabel.setText("Started"); //time consuming code which creates object of another class } Note: I did use java.awt.EventQueue.invokeLater when starting the entire application 回答1: It would behoove you to learn

Java resizing individual components of JPanel

半城伤御伤魂 提交于 2019-12-12 03:28:12
问题 I have a JPanel with Box.createVerticalBox() layout containing five JPanels. (1) Labels, (2) a table (3) a JTextField (4) a JTextArea (5) buttons.On resize: labels should stick to top left corner and keep the same size, JTextField should stick to left size between (2) and (4) and expand to full width of the frame Buttons should stick to bottom right corner and keep the same size, JTable and JTextArea should expand to full width of the frame and equally divide remaining space I've tried

Grey screen on repaint() and revalidate()

不打扰是莪最后的温柔 提交于 2019-12-12 03:17:17
问题 My application gives a grey screen after the timer is run. As advised, I have now a MainPage which extends JFrame and a MenuPage that extends JPanel. I wish to load MenuPage after MainPage is run. repaint() and revalidate() does not work out for me. Please point me in the right direction. import java.awt.*; import java.awt.event.*; import java.io.File; import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; public class MainPage extends JFrame { private