layout-manager

JScrollPane not appearing on JTextArea

血红的双手。 提交于 2019-12-02 12:51:40
I'm trying to add the JScrollPane to my JTextArea, but somehow, it won't appear. I've tried resizing it according to the dimension of the JTextArea, but it doesn't seem to work. Also, notice that I'm using the null layout because I want the full-on flexibility of displaying certain buttons and panels at a pinpoint location. import java.awt.Dimension; import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JScrollPane; import javax.swing.ScrollPaneConstants; import javax.swing.JTextArea; public class PaneTester{ private

Using CardLayout for multiple JPanels and nothing displays

冷暖自知 提交于 2019-12-02 12:00:48
I'm making a simple (and bogus) computer power consumption calculator. I'm using a card layout to put multiple panels in but when I run it, there's just a small window not displaying anything. Here's my long code, I put it all in one class. package my.Project; import java.awt.*; import java.awt.event.*; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.text.DecimalFormat; import javax.swing.*; public class MainProject extends JFrame { CardLayout cl; int motherboardP, oddP, hddP, ssdP, fanP, cpuP, gpuP, monitorP, hoursint; int ramNum, hddNum,

Sizing a JScrollPane in a JTabbedPane in a JFrame

a 夏天 提交于 2019-12-02 11:44:43
I understand from this post Don't Set sizes on a JComponent that you dont set preferred sizes on any component and instead let the layout manager do this for you. My question is, I have a JPanel that I put into a JTabbedPane into a JFrame like this JFrame frame=new JFrame(); JTabbedPane pane=new JTabbedPane(); pane.addTab("Tab 1",new JScrollPane(getJPanel1())); pane.addTab("Tab 2",new JScrollPane(getJPanel2())); frame.setContentPane(pane); Now in this case the JTabbedPane will take the size of the maximum sized component you add to it. Because of this my JScrollPane does not show up at all. I

Java aligning components in panels

筅森魡賤 提交于 2019-12-02 11:19:18
问题 I am trying to add components to SOUTH of a BorderLayout I need it to look like this example. ------------------------------------ | | | | | | | | | | | | |_TxtField|Button_____________Label| So I need a JTextField and a JButton aligned to the left, and a label aligned to the right. How can I accomplish this? Here is my code below, I have tried to do this using nested panels: import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

How to add jzy3d chart to JFrame without making a new one?

隐身守侯 提交于 2019-12-02 10:59:43
问题 There is the following code for making jzy3d chart in JFrame: public class SurfaceViewerFrame extends IconFrame { public SurfaceViewerFrame() { setResizable(false); //System.loadLibrary("lib/jogl2-rc10/gluegen-rt.jar"); Settings.getInstance().setHardwareAccelerated(true); FormLayout layout=new FormLayout("10px, 300px, 10px", "30px, 10px, 20px, 300px, 10px"); CellConstraints сс=new CellConstraints(); JLabel title=new JLabel("Выходная поверхность"); Mapper mapper = new Mapper() { public double

Java aligning components in panels

帅比萌擦擦* 提交于 2019-12-02 07:12:30
I am trying to add components to SOUTH of a BorderLayout I need it to look like this example. ------------------------------------ | | | | | | | | | | | | |_TxtField|Button_____________Label| So I need a JTextField and a JButton aligned to the left, and a label aligned to the right. How can I accomplish this? Here is my code below, I have tried to do this using nested panels: import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class BlackjackGUI{ private JFrame frame; private JPanel panel, panelLeft, panelBottomLeft,

Display cards of CardLayout in random order?

爱⌒轻易说出口 提交于 2019-12-02 06:17:21
问题 I want to have a random order for displaying the cards or screens in my CardLayout. I need guidance on how to accomplish this. What is strategy I should use? I tried using the code below, but it is in a fixed order. I want to be able to choose whichever order I like. EDIT ! Sorry, by random order I did not mean shuffling. But, it is good to know. I want the user of the program to be able to enter some input. Depending on the value of the input, a particular screen/card is displayed. import

How can I use BoxLayout to do this?

邮差的信 提交于 2019-12-02 05:26:41
问题 I've already set up the menu (the centre boxes) perfectly, but I don't know how I can position the label. Currently what is happening is the label is going below the menu options, and the menu options are pushed to the right. Here is what I want to happen: And here is what is happening: Currently I have my boxes centred with: this.setAlignmentX(Component.CENTER_ALIGNMENT); And I have attempted to do the same with my label using: this.setAlignmentX(Component.BOTTOM_ALIGNMENT); this

When creating a BufferedImage from a JPanel (w/o a JFrame), can I also use a layout manager?

落花浮王杯 提交于 2019-12-02 04:47:28
问题 I am trying to create a BufferedImage from a JPanel, without using a JFrame. Yesterday, I was finally able to get the image to appear with help from this community (see below), but now I'm having some layout trouble. All of the components on the BufferedImage begin drawing at 0,0, instead of following the layout manager. Does anyone know of a solution for this problem? Yesterday's question: Can I create a BufferedImage from a JPanel without rendering in a JFrame? In the code below, the two

Adding JPanel to JScrollPane

走远了吗. 提交于 2019-12-02 02:55:35
I have a gui which has a Panel that contains a sequence of labels and TextFields and uses a spring layout(this is the mainPanel) and another Panel that just contains a button(buttonPanel). I am trying to make my mainPanel to have a vertical scrollbar as well. I would like to implement my GUI such that within the JFrame I have 2 panels. The mainPanel appears on the top of the frame and the buttonPanel appears below the mainPanel. My problem is I am not able to make the Panels appear such that the buttonPanel is below the mainPanel and I am also not sure how to add a scrollbar to the mainPanel.