jpanel

JScrollPane doesn't work for my JPanel

二次信任 提交于 2019-12-07 07:35:17
问题 first of all I must say that I have checked these questions and didn't find my answer : 1 , 2 , 3 , 4 , 5 , 6 , 7 and many other questions like so also I have checked these tutorials and examples: 1 , 9 , 10 , 11 and many other sites. but I couldn't fix my problem. and this is the simple kind of my code: public class Question extends JFrame { public Question() { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); setLayout(new BorderLayout()); setSize(d.width, d.height); setResizable

Get shown component in JScrollPane

微笑、不失礼 提交于 2019-12-07 06:56:23
问题 I have a JScrollPane containing a JPanel. I fill this JPanel with many buttons. Is there any possibility to get the currently shown buttons? I know I can access the children of a JPanel via jpanel.getComponents() but those are all components in this pane; I want only the ones that are currently on screen. 回答1: I assume that this container is already visible on the screen, then I suggest 1) to extract JViewPort from JScrollPane, 2) addChangeListener to JViewPort 3) each visible JComponent(s)

JScrollPane does not appear when using it on a JPanel

假如想象 提交于 2019-12-07 04:39:52
问题 I have been trying for hours to find a way to solve the issue, but I had no luck with that. Here is a sample code: import java.awt.BorderLayout; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; public class Example extends JFrame { private static final long serialVersionUID = 1L; public Example() { JPanel contentPane = (JPanel) getContentPane(); contentPane

Java get JPanel Components

懵懂的女人 提交于 2019-12-06 18:00:48
问题 I have a JPanel full of JTextFields... for (int i=0; i<maxPoints; i++) { JTextField textField = new JTextField(); points.add(textField); } How do I later get the JTextFields in that JPanel? Like if I want their values with TextField.getText(); Thanks 回答1: Well bear in mind they didn't get there by them selves ( I think a read some questions about dynamically creating these panels at runtime ) In the answers posted there, someone said you should kept reference to those textfields in an array.

Put JLabel on Component in JPanel

回眸只為那壹抹淺笑 提交于 2019-12-06 15:55:37
I have JPanel which contain a component imageWindow(object of this ) now i want to put a label tag in the center of this imagewindow but i am not able to do so? JPanel imagePanel = new JPanel(); imagePanel.setLayout(new GridBagLayout()); imagePanel.add(ic); //ic is imageWindow obj JLabel l1=new JLabel("First Label."); JPanel example =new JPanel(); example.add(l1); imagePanel.add(example); what i am doing wrong here is screenshow i need to put the label here. i want to put the label at the center but it always coming in the right side what i am doing wrong? You could display the image in a

How to layout? (JFrame, JPanel, etc.)

☆樱花仙子☆ 提交于 2019-12-06 15:31:10
I'm very new to Java Swing and Java overall (my class just got finished on Scanner and basics). I was taught only Swing basics which is "What is a JFrame..etc" and I'm stuck on how to layout or position things. On the image is the layout I desired and could anyone help and teach me how to code it? JFrame with, 5 JPanel components?(4 columns and the order form below) Additionally, when clicking the "CONFIRM" button, I would want a new window to popup. How would I be able to link multiple windows? A common strategy to solve complex computing tasks, is to break them into small, well defined

Programmatically swap two JPanels in JFrame

落花浮王杯 提交于 2019-12-06 13:36:10
I am trying to accomplish the above functionality, and am having little success. I am using GridLayout with 2 columns and 2 rows to show the user a puzzle-like game, where there are 4 (200x200 pixel) JPanels (3 colored, 1 default bgColor) which fill the whole contentPane. Clicking on a colored panel resolves in an assessment if the panel is next to the gray panel. If so, they should swap. I have accomplished every step to the last one, where they swap. Here's the code: public class MainClass extends JFrame { //Generated private static final long serialVersionUID = 4710628273679698058L; private

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(

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(

Getting the colour of where you have clicked on a JPanel?

放肆的年华 提交于 2019-12-06 11:25:39
I only want a method to activate if the pixel that is clicked is white. How would I implement this? Trying to look for a method that returns the colour at a coord, but I can't find one. Depends. If you have got a BufferedImage (or some other Image) you can use its getRGB methods (or getRaster().getPixel ). If you haven't, you can use JPanel's createImage methods and use the returned image to get the pixel data. 来源: https://stackoverflow.com/questions/2623351/getting-the-colour-of-where-you-have-clicked-on-a-jpanel